Hi! I try to understand how comparison works in cdef'd classes, and currently it confuses me a lot.
In sage/modules/vector_rational_dense.pyx there is a class definition Vector_rational_dense. It has a cdef'd method _cmp_c_impl, which is supposed to do the comparison. Now, I inserted the line print "comparing" on top of that method. In that way I found that rather often the comparison method is not called when comparing elements: sage: v = vector(QQ, [0,0,0,0]) sage: w = vector(QQ, [-1,3/2,0,0]) sage: v.parent() is w.parent() True The parents are the same, hence, coercion should not be relevant in this example. sage: v == w False sage: v!=w True sage: v.__cmp__(w) comparing 1 sage: cmp(v,w) 1 Hence, the comparison method is consulted *only* when calling the special method __cmp__ explicitly! So, how else is comparison achieved?? Best regards, Simon -- 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