On Fri, Apr 24, 2009 at 11:05 PM, Alex Ghitza <aghi...@gmail.com> wrote: > > Hi, > > I'm still working on fixing up schemes/generic/morphism.py, and I'm > still having trouble with comparisons. I have written __cmp__() > methods, but they don't seem to be called. Here's a concrete example. > The definition of __cmp__ for SchemeMorphism_id is below: > > {{{ > class SchemeMorphism_id(SchemeMorphism): > """ > The identity morphism from `X` to itself. > """ > > def __cmp__(self, other): > if not isinstance(other, SchemeMorphism_id): > return cmp(type(self), type(other)) > > return cmp(self.parent(), other.parent()) > }}} > > Now if I do > > {{{ > sage: X = Spec(ZZ) > sage: X.identity_morphism().parent() == X.identity_morphism().parent() > True > sage: X.identity_morphism() == X.identity_morphism() > --------------------------------------------------------------------------- > RuntimeError Traceback (most recent call last) > > /home/ghitza/.sage/temp/artin/25555/_home_ghitza__sage_init_sage_0.py > in <module>() > > /opt/sage-devel/local/lib/python2.5/site-packages/sage/structure/element.so > in sage.structure.element.Element.__richcmp__ > (sage/structure/element.c:6021)() > > /opt/sage-devel/local/lib/python2.5/site-packages/sage/structure/element.so > in sage.structure.element.Element._richcmp > (sage/structure/element.c:5385)() > > /opt/sage-devel/local/lib/python2.5/site-packages/sage/structure/coerce.so > in sage.structure.coerce.CoercionModel_cache_maps.canonical_coercion > (sage/structure/coerce.c:7059)() > > RuntimeError: BUG in map, returned None Scheme endomorphism of > Spectrum of Integer Ring > Defn: Identity map <type 'sage.categories.morphism.CallMorphism'> > Call morphism: > From: Set of points of Spectrum of Integer Ring defined over Integer Ring > To: Set of points of Spectrum of Integer Ring defined over Integer Ring > }}} > > > So for some reason the correct __cmp__ is not called here. I've > tracked it down to the following comment in structure/element.pyx: > > # For a *Python* class just define __cmp__ as always. > # But note that when this gets called you can assume that > # both inputs have identical parents. > # > # If your __cmp__ methods are not getting called, verify that the > # canonical_coercion(x,y) is not throwing errors. > > The last part seems to be what's happening. But what does that mean, > and how can I fix it?
Try calling canonical_coercion explicitly. What error is being thrown!? William --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---