dpnp.scipy.linalg.cho_factor

dpnp.scipy.linalg.cho_factor(a, lower=False, overwrite_a=False, check_finite=True)[source]

Compute the Cholesky decomposition of a matrix, to use in dpnp.scipy.linalg.cho_solve.

Returns a matrix containing the Cholesky decomposition, A = L L* or A = U* U of a Hermitian positive-definite matrix a. The return value can be directly used as the first parameter to dpnp.scipy.linalg.cho_solve.

For full documentation refer to scipy.linalg.cho_factor.

Parameters:
a(..., M, M) {dpnp.ndarray, usm_ndarray}

Matrix to be decomposed.

lower{bool, array_like of bool}, optional

Whether to compute the upper or lower triangular Cholesky factorization. An array or a sequence is accepted if all its values are equal.

Default: False.

overwrite_abool, optional

Whether to overwrite data in a (may improve performance).

Default: False.

check_finitebool, 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:
c(..., M, M) dpnp.ndarray

Matrix whose upper or lower triangle contains the Cholesky factor of a. If a is not overwritten, the other triangle is zeroed, otherwise it contains the data of a not used by the decomposition.

lowerbool

Flag indicating whether the factor is in the lower or upper triangle. Unlike SciPy, which returns it as an array tiled to the batch shape, a Python bool is returned.

Raises:
dpnp.linalg.LinAlgError

If the decomposition fails.

ValueError

If a is not square, if lower is empty or its values are not all equal, or if check_finite=True and a contains infinities or NaNs.

Warning

This function synchronizes in order to validate array elements when check_finite=True, and to check the factorization status.

See also

dpnp.scipy.linalg.cho_solve()

Solve a linear set equations using the Cholesky factorization of a matrix.

dpnp.linalg.cholesky()

Cholesky decomposition of a matrix.

Notes

During the finiteness check (if selected), the entire matrix a is checked. During decomposition, a is assumed to be symmetric or Hermitian (as applicable), and only the half selected by option lower is referenced.

Examples

>>> import dpnp as np
>>> A = np.array([[9., 3., 1., 5.], [3., 7., 5., 1.],
...               [1., 5., 9., 2.], [5., 1., 2., 6.]])
>>> c, low = np.scipy.linalg.cho_factor(A)
>>> c
array([[ 3.        ,  1.        ,  0.33333333,  1.66666667],
       [ 0.        ,  2.44948974,  1.90515869, -0.27216553],
       [ 0.        ,  0.        ,  2.29330749,  0.8559528 ],
       [ 0.        ,  0.        ,  0.        ,  1.55418563]])
>>> np.allclose(c.T @ c, A)
array(True)

Batched input:

>>> B = np.stack([A, 2 * A])
>>> c, low = np.scipy.linalg.cho_factor(B, lower=True)
>>> np.allclose(c @ c.mT, B)
array(True)