_add_newdocs.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. from numpy.lib import add_newdoc
  2. add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU',
  3. """
  4. LU factorization of a sparse matrix.
  5. Factorization is represented as::
  6. Pr @ A @ Pc = L @ U
  7. To construct these `SuperLU` objects, call the `splu` and `spilu`
  8. functions.
  9. Attributes
  10. ----------
  11. shape
  12. nnz
  13. perm_c
  14. perm_r
  15. L
  16. U
  17. Methods
  18. -------
  19. solve
  20. Notes
  21. -----
  22. .. versionadded:: 0.14.0
  23. Examples
  24. --------
  25. The LU decomposition can be used to solve matrix equations. Consider:
  26. >>> import numpy as np
  27. >>> from scipy.sparse import csc_matrix, linalg as sla
  28. >>> A = csc_matrix([[1,2,0,4],[1,0,0,1],[1,0,2,1],[2,2,1,0.]])
  29. This can be solved for a given right-hand side:
  30. >>> lu = sla.splu(A)
  31. >>> b = np.array([1, 2, 3, 4])
  32. >>> x = lu.solve(b)
  33. >>> A.dot(x)
  34. array([ 1., 2., 3., 4.])
  35. The ``lu`` object also contains an explicit representation of the
  36. decomposition. The permutations are represented as mappings of
  37. indices:
  38. >>> lu.perm_r
  39. array([0, 2, 1, 3], dtype=int32)
  40. >>> lu.perm_c
  41. array([2, 0, 1, 3], dtype=int32)
  42. The L and U factors are sparse matrices in CSC format:
  43. >>> lu.L.A
  44. array([[ 1. , 0. , 0. , 0. ],
  45. [ 0. , 1. , 0. , 0. ],
  46. [ 0. , 0. , 1. , 0. ],
  47. [ 1. , 0.5, 0.5, 1. ]])
  48. >>> lu.U.A
  49. array([[ 2., 0., 1., 4.],
  50. [ 0., 2., 1., 1.],
  51. [ 0., 0., 1., 1.],
  52. [ 0., 0., 0., -5.]])
  53. The permutation matrices can be constructed:
  54. >>> Pr = csc_matrix((np.ones(4), (lu.perm_r, np.arange(4))))
  55. >>> Pc = csc_matrix((np.ones(4), (np.arange(4), lu.perm_c)))
  56. We can reassemble the original matrix:
  57. >>> (Pr.T @ (lu.L @ lu.U) @ Pc.T).A
  58. array([[ 1., 2., 0., 4.],
  59. [ 1., 0., 0., 1.],
  60. [ 1., 0., 2., 1.],
  61. [ 2., 2., 1., 0.]])
  62. """)
  63. add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('solve',
  64. """
  65. solve(rhs[, trans])
  66. Solves linear system of equations with one or several right-hand sides.
  67. Parameters
  68. ----------
  69. rhs : ndarray, shape (n,) or (n, k)
  70. Right hand side(s) of equation
  71. trans : {'N', 'T', 'H'}, optional
  72. Type of system to solve::
  73. 'N': A @ x == rhs (default)
  74. 'T': A^T @ x == rhs
  75. 'H': A^H @ x == rhs
  76. i.e., normal, transposed, and hermitian conjugate.
  77. Returns
  78. -------
  79. x : ndarray, shape ``rhs.shape``
  80. Solution vector(s)
  81. """))
  82. add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('L',
  83. """
  84. Lower triangular factor with unit diagonal as a
  85. `scipy.sparse.csc_matrix`.
  86. .. versionadded:: 0.14.0
  87. """))
  88. add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('U',
  89. """
  90. Upper triangular factor as a `scipy.sparse.csc_matrix`.
  91. .. versionadded:: 0.14.0
  92. """))
  93. add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('shape',
  94. """
  95. Shape of the original matrix as a tuple of ints.
  96. """))
  97. add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('nnz',
  98. """
  99. Number of nonzero elements in the matrix.
  100. """))
  101. add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('perm_c',
  102. """
  103. Permutation Pc represented as an array of indices.
  104. The column permutation matrix can be reconstructed via:
  105. >>> Pc = np.zeros((n, n))
  106. >>> Pc[np.arange(n), perm_c] = 1
  107. """))
  108. add_newdoc('scipy.sparse.linalg._dsolve._superlu', 'SuperLU', ('perm_r',
  109. """
  110. Permutation Pr represented as an array of indices.
  111. The row permutation matrix can be reconstructed via:
  112. >>> Pr = np.zeros((n, n))
  113. >>> Pr[perm_r, np.arange(n)] = 1
  114. """))