Dear developers,

I was looking through the class DifferentialForm, and there is a note in 
the `__eq__` method pointing that "...most of the execution time is spent" 
in cleaningpu the differential forms
    def __eq__(self, other):
        if type(other) == type(self):
            if self._degree != other._degree:
                return False
            else:
                # TODO: the following two lines are where most of the 
                # execution time is spent.  
                self._cleanup()
                other._cleanup()

                if len(self._components) != len(other._components):
                    return False

                # We compare the component dictionary of both differential 
                # forms, keeping in mind that the set of keys is 
                # lexicographically ordered, so that we can simply iterate 
                # over both dictionaries in one go and compare (key, value) 
                # pairs as we go along.

                for (key1, val1), (key2, val2) in \
                        zip(self._components.iteritems(), \
                            other._components.iteritems()):
                    if key1 != key2 or str(val1) != str(val2):
                        return False
                return True
        else:
            return False



Then, I found the `_cleanup` method

    def _cleanup(self):
        r"""
        Helper function to clean up self, i.e. to remove any
        zero components from the dictionary of components.

        EXAMPLES::

            sage: F = DifferentialForms()
            sage: f = DifferentialForm(F, 1)
            sage: f[0] = 0
            sage: f[1] = 1
            sage: f[2] = 0
            sage: f._dump_all()
            {(2,): 0, (0,): 0, (1,): 1}
            sage: f._cleanup()
            sage: f._dump_all()
            {(1,): 1}

        """
        zeros = []
        
        for comp in self._components:
            if self._components[comp].is_zero():
                zeros.append(comp)
                
        for comp in zeros:  
            del self._components[comp]  

And I wonder... Is it possible to delete directly the `zeros` from `self`? 
I guess it was not done like that because it is not possible!

However, then it occur to me that copying `self` to `other` and then 
reassign to `self` only the notzero component could be faster

Is it possible?

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to