# Ticket #8046: trac_8046_matrix_double_dense.patch

File trac_8046_matrix_double_dense.patch, 13.8 KB (added by Kenny Smith, 11 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 sage/matrix/matrix_rational_dense sage/matrix/matrix_double_dense sage/matrix/matrix_real_double_dense 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 """ Dense matrices using a NumPy backend.  This serves as a base class for dense matrices over Real Double Field and Complex Double Field. Dense matrices using a NumPy backend. This serves as a base class for dense matrices over Real Double Field and Complex Double Field. AUTHORS: - William Stein: many bug fixes and touch ups. EXAMPLES:: sage: b=Mat(RDF,2,3).basis() creation depends on several variables that are set in the subclasses. EXAMPLES: EXAMPLES:: sage: m = Matrix(RDF, [[1,2],[3,4]]) sage: m**2 [ 7.0 10.0] EXAMPLE: In this example, we throw away the current matrix and make a new uninitialized matrix representing the data for the class. new uninitialized matrix representing the data for the class.:: sage: a=matrix(RDF, 3, range(9)) sage: a.__create_matrix__() """ """ Hash this matrix if it's immutable. EXAMPLES: EXAMPLES:: sage: A = matrix(RDF,3,range(1,10)) sage: hash(A) Traceback (most recent call last): def LU_valid(self): r""" Returns \code{True} if the LU form of this matrix has Returns ``True`` if the LU form of this matrix has already been computed. EXAMPLES: EXAMPLES:: sage: A = random_matrix(RDF,3) ; A.LU_valid() False sage: P, L, U = A.LU() The numpy matrix must have already been allocated. EXAMPLES: EXAMPLES:: sage: matrix(RDF,3,range(9)) [0.0 1.0 2.0] [3.0 4.0 5.0] [  0 2.0   0] [  0   0 2.0] TESTS: TESTS:: sage: matrix(RDF,3,0) [] sage: matrix(RDF,3,3,0) """ Return a new uninitialized matrix with same parent as self. INPUT INPUT: nrows -- (default self._nrows) number of rows in returned matrix ncols -- (default self._ncols) number of columns in returned matrix """ Add two matrices together. EXAMPLES: EXAMPLES:: sage: A = matrix(RDF,3,range(1,10)) sage: A+A [ 2.0  4.0  6.0] Return self - right EXAMPLES: EXAMPLES:: sage: A = matrix(RDF,3,range(1,10)) sage: (A-A).is_zero() True """ Negate this matrix EXAMPLES: EXAMPLES:: sage: A = matrix(RDF,3,range(1,10)) sage: -A [-1.0 -2.0 -3.0] """ Multiply self*right as matrices. EXAMPLES EXAMPLES:: sage: A = matrix(RDF,3,range(1,10)) sage: B = matrix(RDF,3,range(1,13)) sage: A*B """ Invert this matrix. EXAMPLES: EXAMPLES:: sage: A = Matrix(RDF, [[10, 0], [0, 100]]) sage: (~A).det() 0.001 [  2.85714285714             3.0  -2.42857142857] [-0.428571428571            -1.0  0.714285714286] Note that if this matrix is (nearly) singular, finding its inverse will not help much and will give slightly different answers on similar platforms depending on the hardware and tuning options given to ATLAS: sage: A = Matrix(RDF, [[1, 0], [0, 0]]) Note that if this matrix is (nearly) singular, finding its inverse will not help much and will give slightly different answers on similar platforms depending on the hardware and tuning options given to ATLAS:: sage: A = matrix(RDF,3,range(1,10));A [1.0 2.0 3.0] True TESTS: TESTS:: sage: ~Matrix(RDF, 0,0) [] sage: ~Matrix(RDF, 0,3) However, round-off errors can make it hard to determine the zero entries of ``U``. .. note:: .. NOTE:: Sometimes this decomposition is written as ``A=P*L*U``, where ``P`` represents the inverse permutation and is Returns a list of the eigenvalues (with multiplicity) of this matrix.  The returned eigenvalues are elements of CDF. EXAMPLES: EXAMPLES:: sage: m = matrix(RDF, 2, 2, [1,2,3,4]) sage: m.eigenvalues() [-0.372281323269, 5.37228132327] real or complex numbers (i.e. RDF or CDF). OUTPUT: Returns a list of triples, each of the form ``(e,[v],1)``, where ``e`` is the eigenvalue, and ``v`` is an associated right eigenvector.  If the matrix is of size `n`, then there def solve_left_LU(self, b): """ Solve the equation A*x = b using LU decomposition. WARNING: This function is broken. See trac 4932. Solve the equation `A x = b` using LU decomposition. .. WARNING:: This function is broken. See trac 4932. INPUT: self -- an invertible matrix b -- a vector - self -- an invertible matrix - b -- a vector NOTES: This method precomputes and stores the LU decomposition before solving. If many equations of the form Ax=b need to be solved for a singe matrix A, then this method should be used instead of solve. The first time this method is called it will compute the LU decomposition.  If the matrix has not changed then subsequent calls will be very fast as the precomputed LU decomposition will be reused. EXAMPLES: .. NOTE:: This method precomputes and stores the LU decomposition before solving. If many equations of the form Ax=b need to be solved for a singe matrix A, then this method should be used instead of solve. The first time this method is called it will compute the LU decomposition.  If the matrix has not changed then subsequent calls will be very fast as the precomputed LU decomposition will be reused. EXAMPLES:: sage: A = matrix(RDF, 3,3, [1,2,5,7.6,2.3,1,1,2,-1]); A [ 1.0  2.0  5.0] [ 7.6  2.3  1.0] TESTS: We test two degenerate cases: We test two degenerate cases:: sage: A = matrix(RDF, 0, 3, []) sage: A.solve_left_LU(vector(RDF,[])) (0.0, 0.0, 0.0) """ Return the determinant of self. ALGORITHM: Use numpy EXAMPLES: ALGORITHM: Use numpy EXAMPLES:: sage: m = matrix(RDF,2,range(4)); m.det() -2.0 sage: m = matrix(RDF,0,[]); m.det() Compute the log of the absolute value of the determinant using LU decomposition. NOTE: This is useful if the usual determinant overflows. EXAMPLES: .. NOTE:: This is useful if the usual determinant overflows. EXAMPLES:: sage: m = matrix(RDF,2,2,range(4)); m [0.0 1.0] [2.0 3.0] [1.0 4.0] [2.0 5.0] :: sage: m = matrix(RDF,0,3); m [] sage: m.transpose() The computed decomposition is cached and returned on subsequent calls. INPUT: A -- a matrix OUTPUT: U, S, V -- immutable matrices such that \$A = U*S*V.conj().transpose()\$ where U and V are orthogonal and S is zero off of the diagonal. Note that if self is m-by-n, then the dimensions of the matrices that this returns are (m,m), (m,n), and (n, n). .. note:: .. NOTE:: If all you need is the singular values of the matrix, see the more convenient :meth:`singular_values`. The computed decomposition is cached and returned on subsequent calls. INPUT: self -- a real matrix A OUTPUT: Q, R -- immutable matrices such that A = Q*R such that the columns of Q are orthogonal (i.e., \$Q^t Q = I\$), and R is upper triangular. """ Return whether this matrix is symmetric, to the given tolerance. EXAMPLES: EXAMPLES:: sage: m = matrix(RDF,2,2,range(4)); m [0.0 1.0] [2.0 3.0] The result is cached, on a per-tolerance and per-algorithm basis. ALGORITHMS:: ALGORITHMS: The naive algorithm simply compares corresponing entries on either side of the diagonal (and on the diagonal itself) to see if they are has columns that form an orthonormal basis composed of eigenvectors of ``self``.  This is known as "orthonormal diagonalization". .. warning:: .. WARNING:: The Schur decomposition is not unique, as there may be numerous choices for the vectors of the orthonormal basis, and consequently matrix must be symmetric and positive definite or an exception will be raised. WARNING:: .. This is deprecated!  Use ``cholesky_decomposition'' instead. .. WARNING:: This is deprecated!  Use :func:`~sage.matrix.matrix2.Matrix.cholesky_decomposition` instead. EXAMPLES:: This method returns a copy of the matrix as a numpy array. It uses the numpy C/api so is very fast. EXAMPLES: EXAMPLES:: sage: m = matrix(RDF,[[1,2],[3,4]]) sage: n = m.numpy() sage: import numpy sage: numpy.array(m).dtype dtype('complex128') TESTS: TESTS:: sage: m = matrix(RDF,0,5,[]); m [] sage: m.numpy() def _replace_self_with_numpy(self,numpy_matrix): """ EXAMPLES: EXAMPLES:: sage: import numpy sage: a = numpy.array([[1,2],[3,4]], 'float64') sage: m = matrix(RDF,2,2,0) def _replace_self_with_numpy32(self,numpy_matrix): """ EXAMPLES: EXAMPLES:: sage: import numpy sage: a = numpy.array([[1,2],[3,4]], 'float32') sage: m = matrix(RDF,2,2,0) Return an integer n such that the absolute value of the determinant of this matrix is at most \$10^n\$. EXAMPLES: EXAMPLES:: sage: a = matrix(RDF, 3, [1,2,5,7,-3,4,2,1,123]) sage: a._hadamard_row_bound() 4 INPUT: algorithm -- 'pade', 'eig', or 'taylor'; the algorithm used to compute the exponential. order -- for Pade or Taylor series algorithms, order is the order of the Pade approximation or the order of the Taylor series used.  The current defaults (from scipy) are 7 for 'pade' and 20 for 'taylor'. EXAMPLES: - algorithm -- 'pade', 'eig', or 'taylor'; the algorithm used to compute the exponential. - order -- for Pade or Taylor series algorithms, order is the order of the Pade approximation or the order of the Taylor series used.  The current defaults (from scipy) are 7 for 'pade' and 20 for 'taylor'. EXAMPLES:: sage: A=matrix(RDF, 2, [1,2,3,4]); A [1.0 2.0] [3.0 4.0] INPUT: - ``eps`` - Cutoff value - ``eps`` - Cutoff value OUTPUT: INPUT: - ``ndigits`` - The precision in number of decimal digits - ``ndigits`` - The precision in number of decimal digits OUTPUT: A modified copy of the matrix EXAMPLES: EXAMPLES:: sage: M=matrix(CDF, [[10.234r + 34.2343jr, 34e10r]]) sage: M