Ticket #11897: trac_11897-doctest-RDF-eigenmatrix.rebased.patch

File trac_11897-doctest-RDF-eigenmatrix.rebased.patch, 5.2 KB (added by leif, 10 years ago)

Rob's patch rebased on Sage 4.7.2.alpha3.

  • sage/matrix/matrix2.pyx

    # HG changeset patch
    # User Rob Beezer <beezer@ups.edu>
    # Date 1317790151 25200
    # Node ID 64fa7cab253fc0efa9944146d699f1ae4b7ac3bb
    # Parent  10f49e34d981dccab46b3c81dc60a14f0ee2d747
    11897: fix failing doctest for RDF eigenmatrix
    
    diff --git a/sage/matrix/matrix2.pyx b/sage/matrix/matrix2.pyx
    a b  
    46304630        This method is only applicable to exact matrices.
    46314631        The "eigenmatrix" routines for matrices with double-precision
    46324632        floating-point entries (``RDF``, ``CDF``) are the best
    4633         alternative.  There are also "eigenmatrix" routines for
     4633        alternative.  (Since some platforms return eigenvectors
     4634        that are the negatives of those given here, this one example
     4635        is not tested here.)  There are also "eigenmatrix" routines for
    46344636        matrices with symbolic entries.  ::
    46354637
    46364638            sage: A = matrix(QQ, 3, 3, range(9))
     
    46454647            [    13.3484692...                 0                 0]
    46464648            [                0    -1.34846922...                 0]
    46474649            [                0                 0                 0]
    4648             sage: eigenvectors = em[1]; eigenvectors
     4650            sage: eigenvectors = em[1]; eigenvectors # not tested
    46494651            [ 0.440242867...  0.567868371...  0.695493875...]
    46504652            [ 0.897878732...  0.278434036... -0.341010658...]
    46514653            [ 0.408248290... -0.816496580...  0.408248290...]
     
    48894891        This method is only applicable to exact matrices.
    48904892        The "eigenmatrix" routines for matrices with double-precision
    48914893        floating-point entries (``RDF``, ``CDF``) are the best
    4892         alternative.  There are also "eigenmatrix" routines for
     4894        alternative.  (Since some platforms return eigenvectors
     4895        that are the negatives of those given here, this one example
     4896        is not tested here.)  There are also "eigenmatrix" routines for
    48934897        matrices with symbolic entries.  ::
    48944898
    48954899            sage: B = matrix(RR, 3, 3, range(9))
     
    49044908            [     13.3484692...                  0                  0]
    49054909            [                 0     -1.34846922...                  0]
    49064910            [                 0                  0                  0]
    4907             sage: eigenvectors = em[1]; eigenvectors
     4911            sage: eigenvectors = em[1]; eigenvectors # not tested
    49084912            [ 0.164763817...  0.799699663...  0.408248290...]
    49094913            [ 0.505774475...  0.104205787... -0.816496580...]
    49104914            [ 0.846785134... -0.591288087...  0.408248290...]
     
    52645268            [0 0 0]
    52655269            sage: P*A == D*P
    52665270            True
     5271           
     5272        TESTS:
     5273       
     5274        For matrices with floating point entries, some platforms will
     5275        return eigenvectors that are negatives of those returned by the
     5276        majority of platforms.  This test accounts for that possibility.
     5277        Running this test independently, without adjusting the eigenvectors
     5278        could indicate this situation on your hardware.  ::
     5279       
     5280            sage: A = matrix(QQ, 3, 3, range(9))
     5281            sage: em = A.change_ring(RDF).eigenmatrix_left()
     5282            sage: evalues = em[0]; evalues
     5283            [    13.3484692...                 0                 0]
     5284            [                0    -1.34846922...                 0]
     5285            [                0                 0 -6.2265089...e-16]
     5286            sage: evectors = em[1];
     5287            sage: for i in range(3):
     5288            ...       scale = evectors[i,0].sign()
     5289            ...       evectors.rescale_row(i, scale)
     5290            sage: evectors
     5291            [ 0.440242867...  0.567868371...  0.695493875...]
     5292            [ 0.897878732...  0.278434036... -0.341010658...]
     5293            [ 0.408248290... -0.816496580...  0.408248290...]                           
    52675294        """
    52685295        from sage.misc.flatten import flatten
    52695296        evecs = self.eigenvectors_left()
     
    53305357            [0 0 0]
    53315358            sage: A*P == P*D
    53325359            True
     5360
     5361        TESTS:
     5362       
     5363        For matrices with floating point entries, some platforms will
     5364        return eigenvectors that are negatives of those returned by the
     5365        majority of platforms.  This test accounts for that possibility.
     5366        Running this test independently, without adjusting the eigenvectors
     5367        could indicate this situation on your hardware.  ::
     5368       
     5369            sage: B = matrix(QQ, 3, 3, range(9))
     5370            sage: em = B.change_ring(RDF).eigenmatrix_right()
     5371            sage: evalues = em[0]; evalues
     5372            [     13.3484692...                  0                  0]
     5373            [                 0     -1.34846922...                  0]
     5374            [                 0                  0 -8.86256604...e-16]
     5375            sage: evectors = em[1];
     5376            sage: for i in range(3):
     5377            ...       scale = evectors[0,i].sign()
     5378            ...       evectors.rescale_col(i, scale)
     5379            sage: evectors
     5380            [ 0.164763817...  0.799699663...  0.408248290...]
     5381            [ 0.505774475...  0.104205787... -0.816496580...]
     5382            [ 0.846785134... -0.591288087...  0.408248290...]
    53335383        """
    53345384        D,P=self.transpose().eigenmatrix_left()
    53355385        return D,P.transpose()