Opened 11 years ago

Last modified 11 years ago

#12290 closed defect

Fix the hash of matrix spaces and improve its performance — at Initial Version

Reported by: Simon King Owned by: jason, was
Priority: critical Milestone: sage-5.0
Component: linear algebra Keywords: hash matrix space unique parent
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

The central assumptions for any hash function is: If two objects are equal then they must have the same hash. That assumption is violated for matrix spaces:

sage: M = MatrixSpace(ZZ, 10)
sage: N = MatrixSpace(ZZ, 10,sparse=True)
sage: N
Full MatrixSpace of 10 by 10 sparse matrices over Integer Ring
sage: M
Full MatrixSpace of 10 by 10 dense matrices over Integer Ring
sage: M == N
True
sage: hash(M)==hash(N)
False

That has to be fixed. Moreover, the hash of matrix spaces is rather sluggish and should thus be improved speed-wise:

sage: %timeit hash(M)
625 loops, best of 3: 13.8 µs per loop

The root of both evils is the generic __hash__ method inherited from SageObject:

    def __hash__(self):
        return hash(self.__repr__())

Change History (1)

Changed 11 years ago by Simon King

Make the hashes of two equal matrix spaces equal. Improve the performance

Note: See TracTickets for help on using tickets.