On 7/26/11 12:03 PM, William Stein wrote:
On Tue, Jul 26, 2011 at 11:55 AM, Rob Beezer mailto:goo...@beezer.cotse.net>> wrote:
I've built a class for vector space morphisms, aka linear
transformations. Mostly this just extends free module morphisms,
while making a few distinctions between behavior for vector spaces
versus modules over rings. Everything seems to be working fine, but I
cannot get equality testing to work.
Equality testing of free module morphisms ends up in a __cmp__()
method for "matrix morphisms." My vector space morphisms extend free
module morphisms, which in turn extend matrix morphisms. If f and
g are two free module morphisms, then
f == g, f.__eq__(g), f.__cmp__(g)
all employ the matrix morphism method __cmp__() and do the right
thing. However, if f and g are two of my vector spaces morphisms,
then f.__cmp__(g) does the right thing, but f == g and
f.__eq__(g) give the wrong answer (False for equal morphisms) and
never "reach down" to employ the __cmp__ method in the base matrix
morphism class.
Any hints, or places to look for guidance? No amount of searching the
developers guide, reference manual, or forums has landed me in the
right place. A 95%-complete patch is up at
http://trac.sagemath.org/sage_trac/ticket/11556
which has all the details, but there is little point in wading through
all that, unless you were interested in reviewing it once
complete. ;-)
Did you overload *both* __cmp__ *and* __hash__?
To fill in some references, please see:
http://docs.python.org/reference/datamodel.html?highlight=__hash__#object.__hash__
and
http://docs.python.org/c-api/typeobj.html?highlight=__hash__#tp_compare
in particular:
"This field is inherited by subtypes together with tp_richcompare and
tp_hash: a subtypes inherits all three of tp_compare, tp_richcompare,
and tp_hash when the subtype’s tp_compare, tp_richcompare, and tp_hash
are all NULL."
I thought there was a note in the Cython documentation about the
relationship between inheriting __cmp__ and __hash__, but I can't seem
to find anything in either the docs or the FAQ.
Jason
--
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org