Ticket #10950: trac_10950-hash_matrices-nt.patch

File trac_10950-hash_matrices-nt.patch, 1.1 KB (added by nthiery, 9 years ago)
  • sage/matrix/matrix_dense.pyx

    # HG changeset patch
    # User Nicolas M. Thiery <nthiery@users.sf.net>
    # Date 1300298728 -3600
    # Node ID d966548caf0cc6d02d29eb98edb125828892d746
    # Parent  04444e4387f8b981c1e1f6f3bcbe00383fc8674c
    The hash function for dense matrices suffers from many collisions with permutation matrices
    
    diff --git a/sage/matrix/matrix_dense.pyx b/sage/matrix/matrix_dense.pyx
    a b cdef class Matrix_dense(matrix.Matrix): 
    6969        if not self._mutability._is_immutable:
    7070            raise TypeError, "mutable matrices are unhashable"
    7171       
    72         v = self._list()
    73         cdef Py_ssize_t i
    74         cdef long h = 0
     72        # v = self._list()
     73        # cdef Py_ssize_t i
     74        # cdef long h = 0
    7575
    76         for i from 0 <= i < len(v):
    77             h = h ^ (i * hash(v[i]))
     76        # for i from 0 <= i < len(v):
     77        #     h = h ^ (i * hash(v[i]))
    7878           
    79         if h == -1:
    80             h = -2
     79        # if h == -1:
     80        #     h = -2
    8181
     82        h = hash(tuple(self._list()))
    8283        self.cache('hash', h)
    8384        return h
    8485