Ticket #8046: trac_8046_matrix_double_dense.patch

File trac_8046_matrix_double_dense.patch, 13.8 KB (added by ksmith, 9 years ago)
  • doc/en/reference/matrices.rst

    # HG changeset patch
    # User Kenneth Smith <kenny.smith@gordon.edu>
    # Date 1326312622 18000
    # Node ID 3260826af34688ba731c644b8ec6d63ba5a2a9e9
    # Parent  9e29a3d84c48c399daaf3920bcb8b17273a0e876
    added matrix.matrix_double_dense.pyx to reference manual and fixed it.
    The fixes only involved syntax errors--content was left alone.
    
    diff --git a/doc/en/reference/matrices.rst b/doc/en/reference/matrices.rst
    a b  
    8181
    8282   sage/matrix/matrix_rational_dense
    8383
     84   sage/matrix/matrix_double_dense
     85
    8486   sage/matrix/matrix_real_double_dense
    8587
    8688   sage/matrix/matrix_complex_double_dense
  • sage/matrix/matrix_double_dense.pyx

    diff --git a/sage/matrix/matrix_double_dense.pyx b/sage/matrix/matrix_double_dense.pyx
    a b  
    11"""
    2 Dense matrices using a NumPy backend.  This serves as a base class for
    3 dense matrices over Real Double Field and Complex Double Field.
     2Dense matrices using a NumPy backend. 
     3
     4
     5This serves as a base class for dense matrices over
     6Real Double Field and Complex Double Field.
    47
    58AUTHORS:
    69
     
    1013
    1114- William Stein: many bug fixes and touch ups.
    1215
     16
    1317EXAMPLES::
    1418
    1519    sage: b=Mat(RDF,2,3).basis()
     
    7478    creation depends on several variables that are set in the
    7579    subclasses.
    7680
    77     EXAMPLES:
     81    EXAMPLES::
     82
    7883        sage: m = Matrix(RDF, [[1,2],[3,4]])
    7984        sage: m**2
    8085        [ 7.0 10.0]
     
    111116       
    112117        EXAMPLE:
    113118        In this example, we throw away the current matrix and make a
    114         new uninitialized matrix representing the data for the class.
     119        new uninitialized matrix representing the data for the class.::
     120
    115121            sage: a=matrix(RDF, 3, range(9))
    116122            sage: a.__create_matrix__()
    117123        """
     
    132138        """
    133139        Hash this matrix if it's immutable.
    134140
    135         EXAMPLES:
     141        EXAMPLES::
     142
    136143            sage: A = matrix(RDF,3,range(1,10))
    137144            sage: hash(A)
    138145            Traceback (most recent call last):
     
    154161
    155162    def LU_valid(self):
    156163        r"""
    157         Returns \code{True} if the LU form of this matrix has
     164        Returns ``True`` if the LU form of this matrix has
    158165        already been computed.
    159        
    160         EXAMPLES:
     166
     167        EXAMPLES::
     168
    161169            sage: A = random_matrix(RDF,3) ; A.LU_valid()
    162170            False
    163171            sage: P, L, U = A.LU()
     
    172180
    173181        The numpy matrix must have already been allocated.
    174182
    175         EXAMPLES:
     183        EXAMPLES::
     184
    176185            sage: matrix(RDF,3,range(9))
    177186            [0.0 1.0 2.0]
    178187            [3.0 4.0 5.0]
     
    182191            [  0 2.0   0]
    183192            [  0   0 2.0]
    184193
    185         TESTS:
     194        TESTS::
     195
    186196            sage: matrix(RDF,3,0)
    187197            []
    188198            sage: matrix(RDF,3,3,0)
     
    287297        """
    288298        Return a new uninitialized matrix with same parent as self.
    289299
    290         INPUT
     300        INPUT:
     301
    291302            nrows -- (default self._nrows) number of rows in returned matrix
    292303            ncols -- (default self._ncols) number of columns in returned matrix
    293304
     
    312323        """
    313324        Add two matrices together.
    314325
    315         EXAMPLES:
     326        EXAMPLES::
     327
    316328            sage: A = matrix(RDF,3,range(1,10))
    317329            sage: A+A
    318330            [ 2.0  4.0  6.0]
     
    335347        Return self - right
    336348
    337349
    338         EXAMPLES:
     350        EXAMPLES::
     351
    339352            sage: A = matrix(RDF,3,range(1,10))
    340353            sage: (A-A).is_zero()
    341354            True
     
    355368        """
    356369        Negate this matrix
    357370
    358         EXAMPLES:
     371        EXAMPLES::
     372
    359373            sage: A = matrix(RDF,3,range(1,10))
    360374            sage: -A
    361375            [-1.0 -2.0 -3.0]
     
    385399        """
    386400        Multiply self*right as matrices.
    387401
    388         EXAMPLES
     402        EXAMPLES::
     403
    389404            sage: A = matrix(RDF,3,range(1,10))
    390405            sage: B = matrix(RDF,3,range(1,13))
    391406            sage: A*B
     
    415430        """
    416431        Invert this matrix.
    417432
    418         EXAMPLES:
     433        EXAMPLES::
     434
    419435            sage: A = Matrix(RDF, [[10, 0], [0, 100]])
    420436            sage: (~A).det()
    421437            0.001
     
    429445            [  2.85714285714             3.0  -2.42857142857]
    430446            [-0.428571428571            -1.0  0.714285714286]
    431447       
    432             Note that if this matrix is (nearly) singular, finding
    433             its inverse will not help much and will give slightly different
    434             answers on similar platforms depending on the hardware
    435             and tuning options given to ATLAS:
    436             sage: A = Matrix(RDF, [[1, 0], [0, 0]])
    437 
    438 
    439 
     448        Note that if this matrix is (nearly) singular, finding
     449        its inverse will not help much and will give slightly different
     450        answers on similar platforms depending on the hardware
     451        and tuning options given to ATLAS::
    440452
    441453            sage: A = matrix(RDF,3,range(1,10));A
    442454            [1.0 2.0 3.0]
     
    447459            True
    448460
    449461
    450         TESTS:
     462        TESTS::
     463
    451464            sage: ~Matrix(RDF, 0,0)
    452465            []
    453466            sage: ~Matrix(RDF, 0,3)
     
    11231136        However, round-off errors can make it hard to determine
    11241137        the zero entries of ``U``.
    11251138
    1126         .. note::
     1139        .. NOTE::
    11271140
    11281141            Sometimes this decomposition is written as ``A=P*L*U``,
    11291142            where ``P`` represents the inverse permutation and is
     
    13941407        Returns a list of the eigenvalues (with multiplicity)
    13951408        of this matrix.  The returned eigenvalues are elements of CDF.
    13961409
    1397         EXAMPLES:
     1410        EXAMPLES::
     1411
    13981412            sage: m = matrix(RDF, 2, 2, [1,2,3,4])
    13991413            sage: m.eigenvalues()
    14001414            [-0.372281323269, 5.37228132327]
     
    14881502        real or complex numbers (i.e. RDF or CDF).
    14891503
    14901504        OUTPUT:
     1505
    14911506        Returns a list of triples, each of the form ``(e,[v],1)``,
    14921507        where ``e`` is the eigenvalue, and ``v`` is an associated
    14931508        right eigenvector.  If the matrix is of size `n`, then there
     
    15441559
    15451560    def solve_left_LU(self, b):
    15461561        """
    1547         Solve the equation A*x = b using LU decomposition.
    1548 
    1549         WARNING: This function is broken. See trac 4932.
     1562        Solve the equation `A x = b` using LU decomposition.
     1563
     1564        .. WARNING::
     1565
     1566            This function is broken. See trac 4932.
    15501567
    15511568        INPUT:
    1552            self -- an invertible matrix
    1553            b -- a vector
     1569
     1570            - self -- an invertible matrix
     1571            - b -- a vector
    15541572       
    1555         NOTES: This method precomputes and stores the LU decomposition
    1556         before solving. If many equations of the form Ax=b need to be
    1557         solved for a singe matrix A, then this method should be used
    1558         instead of solve. The first time this method is called it will
    1559         compute the LU decomposition.  If the matrix has not changed
    1560         then subsequent calls will be very fast as the precomputed LU
    1561         decomposition will be reused.
    1562 
    1563         EXAMPLES:
     1573        .. NOTE::
     1574
     1575            This method precomputes and stores the LU decomposition
     1576            before solving. If many equations of the form Ax=b need to be
     1577            solved for a singe matrix A, then this method should be used
     1578            instead of solve. The first time this method is called it will
     1579            compute the LU decomposition.  If the matrix has not changed
     1580            then subsequent calls will be very fast as the precomputed LU
     1581            decomposition will be reused.
     1582
     1583        EXAMPLES::
     1584
    15641585            sage: A = matrix(RDF, 3,3, [1,2,5,7.6,2.3,1,1,2,-1]); A
    15651586            [ 1.0  2.0  5.0]
    15661587            [ 7.6  2.3  1.0]
     
    15731594           
    15741595
    15751596        TESTS:
    1576         We test two degenerate cases:
     1597
     1598        We test two degenerate cases::
     1599
    15771600            sage: A = matrix(RDF, 0, 3, [])
    15781601            sage: A.solve_left_LU(vector(RDF,[]))
    15791602            (0.0, 0.0, 0.0)
     
    18821905        """
    18831906        Return the determinant of self.
    18841907
    1885         ALGORITHM: Use numpy
    1886 
    1887         EXAMPLES:
     1908        ALGORITHM:
     1909
     1910        Use numpy
     1911
     1912        EXAMPLES::
     1913
    18881914            sage: m = matrix(RDF,2,range(4)); m.det()
    18891915            -2.0
    18901916            sage: m = matrix(RDF,0,[]); m.det()
     
    19111937        Compute the log of the absolute value of the determinant
    19121938        using LU decomposition.
    19131939
    1914         NOTE: This is useful if the usual determinant overflows.
    1915 
    1916         EXAMPLES:
     1940        .. NOTE::
     1941
     1942            This is useful if the usual determinant overflows.
     1943
     1944        EXAMPLES::
     1945
    19171946            sage: m = matrix(RDF,2,2,range(4)); m
    19181947            [0.0 1.0]
    19191948            [2.0 3.0]
     
    19762005            [1.0 4.0]
    19772006            [2.0 5.0]
    19782007
    1979        ::
    19802008            sage: m = matrix(RDF,0,3); m
    19812009            []
    19822010            sage: m.transpose()
     
    20072035        The computed decomposition is cached and returned on subsequent calls.
    20082036
    20092037        INPUT:
     2038
    20102039            A -- a matrix
    20112040           
    20122041        OUTPUT:
     2042
    20132043            U, S, V -- immutable matrices such that $A = U*S*V.conj().transpose()$
    20142044                       where U and V are orthogonal and S is zero off of the diagonal.
    20152045                       
    20162046        Note that if self is m-by-n, then the dimensions of the
    20172047        matrices that this returns are (m,m), (m,n), and (n, n).
    20182048
    2019         .. note::
     2049        .. NOTE::
    20202050
    20212051            If all you need is the singular values of the matrix, see
    20222052            the more convenient :meth:`singular_values`.
     
    21452175        The computed decomposition is cached and returned on subsequent calls.
    21462176
    21472177        INPUT:
     2178
    21482179           self -- a real matrix A
    21492180
    21502181        OUTPUT:
     2182
    21512183           Q, R -- immutable matrices such that A = Q*R such that the columns of Q are
    21522184                   orthogonal (i.e., $Q^t Q = I$), and R is upper triangular.
    21532185
     
    22042236        """
    22052237        Return whether this matrix is symmetric, to the given tolerance.
    22062238
    2207         EXAMPLES:
     2239        EXAMPLES::
     2240
    22082241            sage: m = matrix(RDF,2,2,range(4)); m
    22092242            [0.0 1.0]
    22102243            [2.0 3.0]
     
    24092442
    24102443        The result is cached, on a per-tolerance and per-algorithm basis.
    24112444
    2412         ALGORITHMS::
     2445        ALGORITHMS:
    24132446
    24142447        The naive algorithm simply compares corresponing entries on either
    24152448        side of the diagonal (and on the diagonal itself) to see if they are
     
    25812614        has columns that form an orthonormal basis composed of eigenvectors
    25822615        of ``self``.  This is known as "orthonormal diagonalization".
    25832616
    2584         .. warning::
     2617        .. WARNING::
    25852618
    25862619            The Schur decomposition is not unique, as there may be numerous
    25872620            choices for the vectors of the orthonormal basis, and consequently
     
    28412874        matrix must be symmetric and positive definite or an exception
    28422875        will be raised.
    28432876
    2844         WARNING::
    2845 
    2846         .. This is deprecated!  Use ``cholesky_decomposition'' instead.
     2877        .. WARNING::
     2878
     2879            This is deprecated!  Use :func:`~sage.matrix.matrix2.Matrix.cholesky_decomposition` instead.
    28472880
    28482881        EXAMPLES::
    28492882
     
    28972930        This method returns a copy of the matrix as a numpy array. It
    28982931        uses the numpy C/api so is very fast.
    28992932
    2900         EXAMPLES:
     2933        EXAMPLES::
     2934
    29012935            sage: m = matrix(RDF,[[1,2],[3,4]])
    29022936            sage: n = m.numpy()
    29032937            sage: import numpy
     
    29332967            sage: numpy.array(m).dtype           
    29342968            dtype('complex128')
    29352969
    2936         TESTS:
     2970        TESTS::
     2971
    29372972            sage: m = matrix(RDF,0,5,[]); m
    29382973            []
    29392974            sage: m.numpy()
     
    29472982
    29482983    def _replace_self_with_numpy(self,numpy_matrix):
    29492984        """
    2950         EXAMPLES:
     2985
     2986        EXAMPLES::
     2987
    29512988            sage: import numpy
    29522989            sage: a = numpy.array([[1,2],[3,4]], 'float64')
    29532990            sage: m = matrix(RDF,2,2,0)
     
    29633000
    29643001    def _replace_self_with_numpy32(self,numpy_matrix):
    29653002        """
    2966         EXAMPLES:
     3003
     3004        EXAMPLES::
     3005
    29673006            sage: import numpy
    29683007            sage: a = numpy.array([[1,2],[3,4]], 'float32')
    29693008            sage: m = matrix(RDF,2,2,0)
     
    29813020        Return an integer n such that the absolute value of the
    29823021        determinant of this matrix is at most $10^n$.
    29833022
    2984         EXAMPLES:
     3023        EXAMPLES::
     3024
    29853025            sage: a = matrix(RDF, 3, [1,2,5,7,-3,4,2,1,123])
    29863026            sage: a._hadamard_row_bound()
    29873027            4
     
    30093049
    30103050        INPUT:
    30113051
    3012             algorithm -- 'pade', 'eig', or 'taylor'; the algorithm used to
    3013             compute the exponential.
    3014 
    3015             order -- for Pade or Taylor series algorithms, order is the
    3016             order of the Pade approximation or the order of the Taylor
    3017             series used.  The current defaults (from scipy) are 7 for
    3018             'pade' and 20 for 'taylor'.
    3019 
    3020         EXAMPLES:
     3052            - algorithm -- 'pade', 'eig', or 'taylor'; the algorithm used to
     3053              compute the exponential.
     3054
     3055            - order -- for Pade or Taylor series algorithms, order is the
     3056              order of the Pade approximation or the order of the Taylor
     3057              series used.  The current defaults (from scipy) are 7 for
     3058              'pade' and 20 for 'taylor'.
     3059
     3060        EXAMPLES::
     3061
    30213062            sage: A=matrix(RDF, 2, [1,2,3,4]); A
    30223063            [1.0 2.0]
    30233064            [3.0 4.0]
     
    30933134
    30943135        INPUT:
    30953136
    3096           - ``eps`` - Cutoff value
     3137        - ``eps`` - Cutoff value
    30973138
    30983139        OUTPUT:
    30993140
     
    31373178
    31383179        INPUT:
    31393180
    3140          - ``ndigits`` - The precision in number of decimal digits
     3181        - ``ndigits`` - The precision in number of decimal digits
    31413182
    31423183        OUTPUT:
    31433184
    31443185        A modified copy of the matrix
    31453186
    3146         EXAMPLES:
     3187        EXAMPLES::
    31473188
    31483189            sage: M=matrix(CDF, [[10.234r + 34.2343jr, 34e10r]])
    31493190            sage: M