Ticket #8710: trac_8710-eigenvector-doctest.patch

File trac_8710-eigenvector-doctest.patch, 6.1 KB (added by rbeezer, 13 years ago)
  • sage/matrix/matrix_double_dense.pyx

    # HG changeset patch
    # User Rob Beezer <beezer@ups.edu>
    # Date 1271652660 25200
    # Node ID 4ddb93f40eea558c3cab3fb9c6308699c9937ad8
    # Parent  ef74a6ed21179df343f658c015d7b068bb28c0f3
    Trac 8710: Fix doctests for RDF eigenvectors
    
    diff -r ef74a6ed2117 -r 4ddb93f40eea sage/matrix/matrix_double_dense.pyx
    a b  
    632632        No attempt is made to determine if an eigenvalue has multiplicity
    633633        greater than one, so all the eigenspaces returned have dimension one.
    634634
     635        The SciPy routines used for these computations produce eigenvectors
     636        normalized to have length 1, but on different hardware they may vary
     637        by a sign. So for doctests we have normalized output by creating an
     638        eigenspace with a canonical basis.
     639
    635640        EXAMPLES::
    636        
     641
    637642            sage: m = matrix(RDF, [[-5, 3, 2, 8],[10, 2, 4, -2],[-1, -10, -10, -17],[-2, 7, 6, 13]])
    638643            sage: spectrum = m.eigenspaces_left()
    639             sage: spectrum[0]
    640             (2.0, Vector space of degree 4 and dimension 1 over Real Double Field
    641             User basis matrix:
    642             [0.5 0.5 0.5 0.5])
     644            sage: spectrum[0][0]
     645            2.0
     646            sage: (RDF^4).subspace(spectrum[0][1].basis())
     647            Vector space of degree 4 and dimension 1 over Real Double Field
     648            Basis matrix:
     649            [1.0 1.0 1.0 1.0]
    643650
    644651            sage: e, V = spectrum[2]
    645652            sage: v = V.basis()[0]
     
    688695        No attempt is made to determine if an eigenvalue has multiplicity
    689696        greater than one, so all the eigenspaces returned have dimension one.
    690697
     698        The SciPy routines used for these computations produce eigenvectors
     699        normalized to have length 1, but on different hardware they may vary
     700        by a sign. So for doctests we have normalized output by creating an
     701        eigenspace with a canonical basis.
     702
     703
    691704        EXAMPLES::
    692705
    693706            sage: m = matrix(RDF, [[-9, -14, 19, -74],[-1, 2, 4, -11],[-4, -12, 6, -32],[0, -2, -1, 1]])
     
    697710            [ -4.0 -12.0   6.0 -32.0]
    698711            [  0.0  -2.0  -1.0   1.0]
    699712            sage: spectrum = m.eigenspaces_right()
    700             sage: spectrum[0]
    701             (2.0, Vector space of degree 4 and dimension 1 over Real Double Field
    702             User basis matrix:
    703             [ 0.258198889747 -0.516397779494  0.774596669241  0.258198889747])
     713            sage: spectrum[0][0]
     714            2.0
     715            sage: (RDF^4).subspace(spectrum[0][1].basis())
     716            Vector space of degree 4 and dimension 1 over Real Double Field
     717            Basis matrix:
     718            [ 1.0 -2.0  3.0  1.0]
    704719
    705720            sage: e, V = spectrum[2]
    706721            sage: v = V.basis()[0]
     
    782797        eigenvalues or zero eigenvalues should be addressed in the
    783798        calling routine.
    784799
     800        The SciPy routines used for these computations produce eigenvectors
     801        normalized to have length 1, but on different hardware they may vary
     802        by a sign. So for doctests we have normalized output by forcing their
     803        eigenvectors to have their first non-zero entry equal to one.
     804
    785805        EXAMPLES::
    786806
    787807            sage: m = matrix(RDF, [[-5, 3, 2, 8],[10, 2, 4, -2],[-1, -10, -10, -17],[-2, 7, 6, 13]])
     
    791811            [ -1.0 -10.0 -10.0 -17.0]
    792812            [ -2.0   7.0   6.0  13.0]
    793813            sage: spectrum = m.left_eigenvectors()
     814            sage: for i in range(len(spectrum)):
     815            ...     spectrum[i][1][0]=matrix(RDF, spectrum[i][1]).echelon_form()[0]
    794816            sage: spectrum[0]
    795             (2.0, [(0.5, 0.5, 0.5, 0.5)], 1)
     817            (2.0, [(1.0, 1.0, 1.0, 1.0)], 1)
    796818            sage: spectrum[1]
    797             (1.0, [(-0.615457454897, -0.492365963917, -0.492365963917, -0.369274472938)], 1)
     819            (1.0, [(1.0, 0.8, 0.8, 0.6)], 1)
    798820            sage: spectrum[2]
    799             (-2.0, [(-0.800640769025, -0.32025630761, -0.480384461415, -0.160128153805)], 1)
     821            (-2.0, [(1.0, 0.4, 0.6, 0.2)], 1)
    800822            sage: spectrum[3]
    801             (-1.0, [(0.316227766017, 0.316227766017, 0.632455532034, 0.632455532034)], 1)
     823            (-1.0, [(1.0, 1.0, 2.0, 2.0)], 1)
    802824        """
    803825        if not self.is_square():
    804826            raise ArithmeticError, "self must be a square matrix"
     
    835857        eigenvalues or zero eigenvalues should be addressed in the
    836858        calling routine.
    837859
     860        The SciPy routines used for these computations produce eigenvectors
     861        normalized to have length 1, but on different hardware they may vary
     862        by a sign. So for doctests we have normalized output by forcing their
     863        eigenvectors to have their first non-zero entry equal to one.
     864
    838865        EXAMPLES::
    839        
     866
    840867            sage: m = matrix(RDF, [[-9, -14, 19, -74],[-1, 2, 4, -11],[-4, -12, 6, -32],[0, -2, -1, 1]])
    841868            sage: m
    842869            [ -9.0 -14.0  19.0 -74.0]
     
    844871            [ -4.0 -12.0   6.0 -32.0]
    845872            [  0.0  -2.0  -1.0   1.0]
    846873            sage: spectrum = m.right_eigenvectors()
     874            sage: for i in range(len(spectrum)):
     875            ...     spectrum[i][1][0]=matrix(RDF, spectrum[i][1]).echelon_form()[0]
    847876            sage: spectrum[0]
    848             (2.0, [(0.258198889747, -0.516397779494, 0.774596669241, 0.258198889747)], 1)
     877            (2.0, [(1.0, -2.0, 3.0, 1.0)], 1)
    849878            sage: spectrum[1]
    850             (1.0, [(-0.547722557505, 0.36514837167, -0.73029674334, -0.182574185835)], 1)
     879            (1.0, [(1.0, -0.666666666667, 1.33333333333, 0.333333333333)], 1)
    851880            sage: spectrum[2]
    852             (-2.0, [(0.693375245282, -0.138675049056, 0.693375245282, 0.138675049056)], 1)
     881            (-2.0, [(1.0, -0.2, 1.0, 0.2)], 1)
    853882            sage: spectrum[3]
    854             (-1.0, [(0.426401432711, -0.213200716356, 0.852802865422, 0.213200716356)], 1)
    855             """
     883            (-1.0, [(1.0, -0.5, 2.0, 0.5)], 1)
     884        """
    856885        if not self.is_square():
    857886            raise ArithmeticError, "self must be a square matrix"
    858887        if self._nrows == 0: