Ticket #11544: trac_11544-avoid-hash-of-matrix-entries.patch

File trac_11544-avoid-hash-of-matrix-entries.patch, 2.1 KB (added by rbeezer, 10 years ago)
  • sage/matrix/matrix0.pyx

    # HG changeset patch
    # User Rob Beezer <beezer@ups.edu>
    # Date 1309012828 25200
    # Node ID 7bd1279f21386471abc5c35f499a770b84036dc0
    # Parent  6ca08864b80c1e04599ba23ba295bfcf6a61f19b
    11544: avoid hashing matrix entries when generating string representation
    
    diff -r 6ca08864b80c -r 7bd1279f2138 sage/matrix/matrix0.pyx
    a b  
    16191619          elements of the base ring and values the desired string
    16201620          representation.  Values sent in via the other keyword
    16211621          arguments will override values in the dictionary.
     1622          Use of a dictionary can potentially take a very long time
     1623          due to the need to hash entries of the matrix.  Matrices
     1624          with entries from ``QQbar`` are one example.
    16221625
    16231626          If ``rep_mapping`` is callable then it will be called with
    16241627          elements of the matrix and must return a string.  Simply
     
    16631666            '[+ .]\n[+ -]'
    16641667            sage: M.str(repr)
    16651668            '[ 1  0]\n[ 2 -1]'
     1669
     1670        TESTS:
     1671
     1672        Prior to Trac #11544 this could take a full minute to run (2011). ::
     1673
     1674            sage: A = matrix(QQ, 4, 4, [1, 2, -2, 2, 1, 0, -1, -1, 0, -1, 1, 1, -1, 2, 1/2, 0])
     1675            sage: e = A.eigenvalues()[3]
     1676            sage: K = (A-e).kernel()
     1677            sage: P = K.basis_matrix()
     1678            sage: P.str()
     1679            '[             1.000000000000000? + 0.?e-17*I -2.116651487479748? + 0.0255565807096352?*I -0.2585224251020429? + 0.288602340904754?*I -0.4847545623533090? - 1.871890760086142?*I]'
    16661680        """
    16671681        #x = self.fetch('repr')  # too confusing!!
    16681682        #if not x is None: return x
     
    16921706            # Override the usual representations with those specified
    16931707            if callable(rep_mapping):
    16941708                rep = rep_mapping(x)
    1695             elif rep_mapping.has_key(x):
     1709            # avoid hashing entries, especially algebraic numbers
     1710            elif rep_mapping and rep_mapping.has_key(x):
    16961711                rep = rep_mapping.get(x)
    16971712            else:
    16981713                rep = repr(x)