#17890: Remove _(rich)cmp_c_impl
-------------------------------------+-------------------------------------
Reporter: jdemeyer | Owner:
Type: enhancement | Status: needs_review
Priority: major | Milestone: sage-6.6
Component: cython | Resolution:
Keywords: | Merged in:
Authors: Jeroen Demeyer | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
u/jdemeyer/ticket/17890 | 17bd067153ad40ced061147390687f514a7f7cba
Dependencies: | Stopgaps:
-------------------------------------+-------------------------------------
Comment (by vdelecroix):
I did some experimentations with Python classes. The conclusion is:
just define `_cmp_` and `_richcmp_` (even though you redefine
`__hash__`)
Then:
- rich comparisons and comparisons work when it involves elements with
the same parent (i.e. the newly defined `_cmp_` and `_richcmp_` gets
called)
- rich comparisons involving coercion is fine
- comparison involving coercion is '''wrong''': if you call {{{cmp(a,b)}}}
with `a` and `b` between two parents `A` and `B` and a coercion `B -> A`
then `Element.__richcmp__` is called instead of `Element.__cmp__`.
Actually, this is not only a bug in Python but also in Cython! I added
print statement in each comparisons function in `Element` and see
{{{
sage: cmp(1,1/3)
Element._richcmp(1,1/3,2)
Element._richcmp(1,1/3,2)
Element._richcmp_(1,1/3,2)
Element._richcmp(1,1/3,0)
Element._richcmp(1,1/3,0)
Element._richcmp_(1,1/3,0)
Element._richcmp(1,1/3,4)
Element._richcmp(1,1/3,4)
Element._richcmp_(1,1/3,4)
1
}}}
Vincent
--
Ticket URL: <http://trac.sagemath.org/ticket/17890#comment:27>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" 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-trac.
For more options, visit https://groups.google.com/d/optout.