Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.9/dist-packages/scipy/sparse/linalg/_dsolve/_add_newdocs.py: 100%
9 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-14 06:37 +0000
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-14 06:37 +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
38 >>> from scipy.sparse.linalg import splu
39 >>> A = csc_matrix([[1,2,0,4], [1,0,0,1], [1,0,2,1], [2,2,1,0.]])
41 This can be solved for a given right-hand side:
43 >>> lu = splu(A)
44 >>> b = np.array([1, 2, 3, 4])
45 >>> x = lu.solve(b)
46 >>> A.dot(x)
47 array([ 1., 2., 3., 4.])
49 The ``lu`` object also contains an explicit representation of the
50 decomposition. The permutations are represented as mappings of
51 indices:
53 >>> lu.perm_r
54 array([2, 1, 3, 0], dtype=int32) # may vary
55 >>> lu.perm_c
56 array([0, 1, 3, 2], dtype=int32) # may vary
58 The L and U factors are sparse matrices in CSC format:
60 >>> lu.L.toarray()
61 array([[ 1. , 0. , 0. , 0. ], # may vary
62 [ 0.5, 1. , 0. , 0. ],
63 [ 0.5, -1. , 1. , 0. ],
64 [ 0.5, 1. , 0. , 1. ]])
65 >>> lu.U.toarray()
66 array([[ 2. , 2. , 0. , 1. ], # may vary
67 [ 0. , -1. , 1. , -0.5],
68 [ 0. , 0. , 5. , -1. ],
69 [ 0. , 0. , 0. , 2. ]])
71 The permutation matrices can be constructed:
73 >>> Pr = csc_matrix((np.ones(4), (lu.perm_r, np.arange(4))))
74 >>> Pc = csc_matrix((np.ones(4), (np.arange(4), lu.perm_c)))
76 We can reassemble the original matrix:
78 >>> (Pr.T @ (lu.L @ lu.U) @ Pc.T).toarray()
79 array([[ 1., 2., 0., 4.],
80 [ 1., 0., 0., 1.],
81 [ 1., 0., 2., 1.],
82 [ 2., 2., 1., 0.]])
83 """)
85add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('solve',
86 """
87 solve(rhs[, trans])
89 Solves linear system of equations with one or several right-hand sides.
91 Parameters
92 ----------
93 rhs : ndarray, shape (n,) or (n, k)
94 Right hand side(s) of equation
95 trans : {'N', 'T', 'H'}, optional
96 Type of system to solve::
98 'N': A @ x == rhs (default)
99 'T': A^T @ x == rhs
100 'H': A^H @ x == rhs
102 i.e., normal, transposed, and hermitian conjugate.
104 Returns
105 -------
106 x : ndarray, shape ``rhs.shape``
107 Solution vector(s)
108 """))
110add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('L',
111 """
112 Lower triangular factor with unit diagonal as a
113 `scipy.sparse.csc_matrix`.
115 .. versionadded:: 0.14.0
116 """))
118add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('U',
119 """
120 Upper triangular factor as a `scipy.sparse.csc_matrix`.
122 .. versionadded:: 0.14.0
123 """))
125add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('shape',
126 """
127 Shape of the original matrix as a tuple of ints.
128 """))
130add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('nnz',
131 """
132 Number of nonzero elements in the matrix.
133 """))
135add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('perm_c',
136 """
137 Permutation Pc represented as an array of indices.
139 The column permutation matrix can be reconstructed via:
141 >>> Pc = np.zeros((n, n))
142 >>> Pc[np.arange(n), perm_c] = 1
143 """))
145add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('perm_r',
146 """
147 Permutation Pr represented as an array of indices.
149 The row permutation matrix can be reconstructed via:
151 >>> Pr = np.zeros((n, n))
152 >>> Pr[perm_r, np.arange(n)] = 1
153 """))