mindspore.scipy.linalg.lu_factor

mindspore.scipy.linalg.lu_factor(a, overwrite_a=False, check_finite=True)[source]

Compute pivoted LU decomposition of a square matrix, and its outputs can be directly used as the inputs of lu_solve. The decomposition is:

\[A = P L U\]

where \(P\) is a permutation matrix, \(L\) lower triangular with unit diagonal elements, and \(U\) upper triangular.

Parameters
  • a (Tensor) – square matrix of \((M, M)\) to decompose. Note that if the input tensor is not a float, then it will be casted to :class:’mstype.float32’.

  • overwrite_a (bool, optional) – Whether to overwrite data in \(A\) (may increase performance). Default: False.

  • check_finite (bool, optional) – Whether to check that the input matrix contains only finite numbers. Disabling may give a performance gain, but may result in problems (crashes, non-termination) if the inputs do contain infinities or NaNs. Default: True.

Returns

  • Tensor, a square matrix of \((N, N)\) containing U in its upper triangle, and L in its lower triangle. The unit diagonal elements of L are not stored.

  • Tensor, \((N,)\) pivot indices representing the permutation matrix P: the i-th element value j in the indices indicates that row i of matrix was interchanged with row j.

Raises

ValueError – If \(a\) is not square.

Supported Platforms:

CPU GPU

Examples

>>> import numpy as onp
>>> from mindspore.common import Tensor
>>> from mindspore.scipy.linalg import lu_factor
>>> A = Tensor(onp.array([[2, 5, 8, 7], [5, 2, 2, 8], [7, 5, 6, 6], [5, 4, 4, 8]]).astype(onp.float64))
>>> lu, piv = lu_factor(A)
>>> lu
Tensor(shape=[4, 4], dtype=Float64, value=
[[ 7.00000000e+00,  5.00000000e+00,  6.00000000e+00,  6.00000000e+00],
 [ 2.85714286e-01,  3.57142857e+00,  6.28571429e+00,  5.28571429e+00],
 [ 7.14285714e-01,  1.20000000e-01, -1.04000000e+00,  3.08000000e+00],
 [ 7.14285714e-01, -4.40000000e-01, -4.61538462e-01,  7.46153846e+00]])
>>> piv
Tensor(shape=[4], dtype=Int32, value= [2, 2, 3, 3])