Hi!

Matrix spaces of dense and sparse matrices are equal and are thus not
unique parents:
  sage: M1 = MatrixSpace(ZZ,2,sparse=True)
  sage: M2 = MatrixSpace(ZZ,2,sparse=False)
  sage: M1 is M2
  False
  sage: M1==M2
  True

Fine. But what should be really bad: They violate the assumption that
equal objects have equal hash.
  sage: hash(M1)==hash(M2)
  False

By consequence, the two equal matrix spaces will correspond to
different items of dictionaries:
  sage: D = {M1:1,M2:2}
  sage: len(D)
  2

I think that it is an apparent bug. Therefore, at #12290, I am fixing
the hash values (and moreover I speed-up the hash of matrix spaces
considerably).

However, it seems that the coercion framework relies on the bug.
Namely, when fixing it, one gets
  sage: A = matrix(ZZ, 5, range(30), sparse=False)
  sage: B = matrix(ZZ, 5, range(30), sparse=True)
  sage: C = matrix(QQ, 5, range(30), sparse=True)
  sage: A.elementwise_product(C).is_dense()
  True
  sage: B.elementwise_product(C).is_sparse()
 
---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent
call last)
  ...
  TypeError: no common canonical parent for objects with parents:
'Full MatrixSpace of 5 by 6 sparse matrices over Integer Ring' and
'Full MatrixSpace of 5 by 6 sparse matrices over Rational Field'

The problem can be fixed by making matrix spaces unique parents (but I
didn't check yet whether it creates other problems).

Question to you: Do you see an obvious reason why matrix spaces should
not be unique parents?

Best regards,
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

Reply via email to