On Wed, Oct 6, 2010 at 9:12 AM, Simon King <[email protected]> wrote: > Hi Jeroen! > > On Oct 6, 8:15 am, Jeroen Demeyer <[email protected]> wrote: >> More precisely, I am looking for the location of the code which compares >> a Matrix_modn_sparse with a Matrix_modn_dense. I.e. I want to see the >> code for >> >> sage: L = matrix(GF(43), 3, 3, range(9), sparse=True) >> sage: R = matrix(GF(43), 3, 3, range(9)) >> sage: type(L) >> <type 'sage.matrix.matrix_modn_sparse.Matrix_modn_sparse'> >> sage: type(R) >> <type 'sage.matrix.matrix_modn_dense.Matrix_modn_dense'> >> sage: L==R # Where is this implemented? >> True > > If I am not mistaken, there is a generic __cmp__ (double underscore) > method at work, that will first send both arguments to a common > parent, by means of Sage's coercion model, and that then calls _cmp_ > (single underscore). > > So, if you ever want to implement comparison of elements of a parent > structure, I recall that you must *not* implement __cmp__ but _cmp_. > > In this case, the common parent is the matrix space of *dense* 3x3 > matrices over GF(43). > > So, relevant is the _cmp_ method of the matrix R (since while > comparing L and R, L is sent to R's parent). > > "R._cmp_?" shows that the comparison is forwarded to yet another > method (WHY??), namely _cmp_c_impl. > > And I am afraid I can not find _cmp_c_impl. > > So, it is indeed confusing.
Indeed. Perhaps Jeroen's main point is that it is supposed to be always possible to find out ow something is implemented using ??, but in some cases like this that's not possible -- instead you do have to know more about the structure of the Sage library. A second point: if Simon is right then whenever a dense matrix is compared to a sparse one, the sparse one is first converted to a dense equivalent. That does not look very efficient to me, though it is true that when both are of size mxn then all m*n entries of the dense one might need to be looked at. John > > Cheers, > Simon > > -- > To post to this group, send an email to [email protected] > To unsubscribe from this group, send an email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/sage-devel > URL: http://www.sagemath.org > -- To post to this group, send an email to [email protected] To unsubscribe from this group, send an email to [email protected] For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org
