Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/scipy/sparse/linalg/_dsolve/_add_newdocs.py: 100%
9 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-12 06:31 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-12 06:31 +0000
1from numpy.lib import add_newdoc
3add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU',
4 """
5 LU factorization of a sparse matrix.
7 Factorization is represented as::
9 Pr @ A @ Pc = L @ U
11 To construct these `SuperLU` objects, call the `splu` and `spilu`
12 functions.
14 Attributes
15 ----------
16 shape
17 nnz
18 perm_c
19 perm_r
20 L
21 U
23 Methods
24 -------
25 solve
27 Notes
28 -----
30 .. versionadded:: 0.14.0
32 Examples
33 --------
34 The LU decomposition can be used to solve matrix equations. Consider:
36 >>> import numpy as np
37 >>> from scipy.sparse import csc_matrix, linalg as sla
38 >>> A = csc_matrix([[1,2,0,4],[1,0,0,1],[1,0,2,1],[2,2,1,0.]])
40 This can be solved for a given right-hand side:
42 >>> lu = sla.splu(A)
43 >>> b = np.array([1, 2, 3, 4])
44 >>> x = lu.solve(b)
45 >>> A.dot(x)
46 array([ 1., 2., 3., 4.])
48 The ``lu`` object also contains an explicit representation of the
49 decomposition. The permutations are represented as mappings of
50 indices:
52 >>> lu.perm_r
53 array([0, 2, 1, 3], dtype=int32)
54 >>> lu.perm_c
55 array([2, 0, 1, 3], dtype=int32)
57 The L and U factors are sparse matrices in CSC format:
59 >>> lu.L.A
60 array([[ 1. , 0. , 0. , 0. ],
61 [ 0. , 1. , 0. , 0. ],
62 [ 0. , 0. , 1. , 0. ],
63 [ 1. , 0.5, 0.5, 1. ]])
64 >>> lu.U.A
65 array([[ 2., 0., 1., 4.],
66 [ 0., 2., 1., 1.],
67 [ 0., 0., 1., 1.],
68 [ 0., 0., 0., -5.]])
70 The permutation matrices can be constructed:
72 >>> Pr = csc_matrix((np.ones(4), (lu.perm_r, np.arange(4))))
73 >>> Pc = csc_matrix((np.ones(4), (np.arange(4), lu.perm_c)))
75 We can reassemble the original matrix:
77 >>> (Pr.T @ (lu.L @ lu.U) @ Pc.T).A
78 array([[ 1., 2., 0., 4.],
79 [ 1., 0., 0., 1.],
80 [ 1., 0., 2., 1.],
81 [ 2., 2., 1., 0.]])
82 """)
84add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('solve',
85 """
86 solve(rhs[, trans])
88 Solves linear system of equations with one or several right-hand sides.
90 Parameters
91 ----------
92 rhs : ndarray, shape (n,) or (n, k)
93 Right hand side(s) of equation
94 trans : {'N', 'T', 'H'}, optional
95 Type of system to solve::
97 'N': A @ x == rhs (default)
98 'T': A^T @ x == rhs
99 'H': A^H @ x == rhs
101 i.e., normal, transposed, and hermitian conjugate.
103 Returns
104 -------
105 x : ndarray, shape ``rhs.shape``
106 Solution vector(s)
107 """))
109add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('L',
110 """
111 Lower triangular factor with unit diagonal as a
112 `scipy.sparse.csc_matrix`.
114 .. versionadded:: 0.14.0
115 """))
117add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('U',
118 """
119 Upper triangular factor as a `scipy.sparse.csc_matrix`.
121 .. versionadded:: 0.14.0
122 """))
124add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('shape',
125 """
126 Shape of the original matrix as a tuple of ints.
127 """))
129add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('nnz',
130 """
131 Number of nonzero elements in the matrix.
132 """))
134add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('perm_c',
135 """
136 Permutation Pc represented as an array of indices.
138 The column permutation matrix can be reconstructed via:
140 >>> Pc = np.zeros((n, n))
141 >>> Pc[np.arange(n), perm_c] = 1
142 """))
144add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('perm_r',
145 """
146 Permutation Pr represented as an array of indices.
148 The row permutation matrix can be reconstructed via:
150 >>> Pr = np.zeros((n, n))
151 >>> Pr[perm_r, np.arange(n)] = 1
152 """))