cupyx.scipy.linalg.lu_factor¶
-
cupyx.scipy.linalg.
lu_factor
(a, overwrite_a=False, check_finite=True)[source]¶ LU decomposition.
Decompose a given two-dimensional square matrix into
P * L * U
, whereP
is a permutation matrix,L
lower-triangular with unit diagonal elements, andU
upper-triangular matrix. Note that in the current implementationa
must be a real matrix, and onlynumpy.float32
andnumpy.float64
are supported.- Parameters
a (cupy.ndarray) – The input matrix with dimension
(M, N)
overwrite_a (bool) – Allow overwriting data in
a
(may enhance performance)check_finite (bool) – Whether to check that the input matrices contain 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.
- Returns
(lu, piv)
wherelu
is acupy.ndarray
storingU
in its upper triangle, andL
without unit diagonal elements in its lower triangle, andpiv
is acupy.ndarray
storing pivot indices representing permutation matrixP
. For0 <= i < min(M,N)
, rowi
of the matrix was interchanged with rowpiv[i]
- Return type
See also
Note
Current implementation returns result different from SciPy when the matrix singular. SciPy returns an array containing
0.
while the current implementation returns an array containingnan
.>>> import numpy as np >>> import scipy.linalg >>> scipy.linalg.lu_factor(np.array([[0, 1], [0, 0]], dtype=np.float32)) (array([[0., 1.], [0., 0.]], dtype=float32), array([0, 1], dtype=int32))
>>> import cupy as cp >>> import cupyx.scipy.linalg >>> cupyx.scipy.linalg.lu_factor(cp.array([[0, 1], [0, 0]], dtype=cp.float32)) (array([[ 0., 1.], [nan, nan]], dtype=float32), array([0, 1], dtype=int32))