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.4, created at 2024-03-22 06:44 +0000

1from numpy.lib import add_newdoc 

2 

3add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', 

4 """ 

5 LU factorization of a sparse matrix. 

6 

7 Factorization is represented as:: 

8 

9 Pr @ A @ Pc = L @ U 

10 

11 To construct these `SuperLU` objects, call the `splu` and `spilu` 

12 functions. 

13 

14 Attributes 

15 ---------- 

16 shape 

17 nnz 

18 perm_c 

19 perm_r 

20 L 

21 U 

22 

23 Methods 

24 ------- 

25 solve 

26 

27 Notes 

28 ----- 

29 

30 .. versionadded:: 0.14.0 

31 

32 Examples 

33 -------- 

34 The LU decomposition can be used to solve matrix equations. Consider: 

35 

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.]]) 

40 

41 This can be solved for a given right-hand side: 

42 

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.]) 

48 

49 The ``lu`` object also contains an explicit representation of the 

50 decomposition. The permutations are represented as mappings of 

51 indices: 

52 

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 

57 

58 The L and U factors are sparse matrices in CSC format: 

59 

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. ]]) 

70 

71 The permutation matrices can be constructed: 

72 

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))) 

75 

76 We can reassemble the original matrix: 

77 

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 """) 

84 

85add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('solve', 

86 """ 

87 solve(rhs[, trans]) 

88 

89 Solves linear system of equations with one or several right-hand sides. 

90 

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:: 

97 

98 'N': A @ x == rhs (default) 

99 'T': A^T @ x == rhs 

100 'H': A^H @ x == rhs 

101 

102 i.e., normal, transposed, and hermitian conjugate. 

103 

104 Returns 

105 ------- 

106 x : ndarray, shape ``rhs.shape`` 

107 Solution vector(s) 

108 """)) 

109 

110add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('L', 

111 """ 

112 Lower triangular factor with unit diagonal as a 

113 `scipy.sparse.csc_matrix`. 

114 

115 .. versionadded:: 0.14.0 

116 """)) 

117 

118add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('U', 

119 """ 

120 Upper triangular factor as a `scipy.sparse.csc_matrix`. 

121 

122 .. versionadded:: 0.14.0 

123 """)) 

124 

125add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('shape', 

126 """ 

127 Shape of the original matrix as a tuple of ints. 

128 """)) 

129 

130add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('nnz', 

131 """ 

132 Number of nonzero elements in the matrix. 

133 """)) 

134 

135add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('perm_c', 

136 """ 

137 Permutation Pc represented as an array of indices. 

138 

139 The column permutation matrix can be reconstructed via: 

140 

141 >>> Pc = np.zeros((n, n)) 

142 >>> Pc[np.arange(n), perm_c] = 1 

143 """)) 

144 

145add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('perm_r', 

146 """ 

147 Permutation Pr represented as an array of indices. 

148 

149 The row permutation matrix can be reconstructed via: 

150 

151 >>> Pr = np.zeros((n, n)) 

152 >>> Pr[perm_r, np.arange(n)] = 1 

153 """))