This is a pre-release version (2.0.0.dev0+git20260907.41eeb59).Go to latest (1.18.0)
{ } Raw JSON

bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / linalg / _decomp_cholesky / cho_factor

function

scipy.linalg._decomp_cholesky:cho_factor

source: build-install/usr/lib/python3.14/site-packages/scipy/linalg/_decomp_cholesky.py:125

Signature

def cho_factor(a, lower = False, overwrite_a = False, check_finite = True)

Summary

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

Extended Summary

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 cho_solve.

Parameters

a : (..., M, M) array_like

Matrix to be decomposed

lower : bool, optional

Whether to compute the upper or lower triangular Cholesky factorization. During decomposition, only the selected half of the matrix is referenced. (Default: upper-triangular)

overwrite_a : bool, optional

Whether to overwrite data in a (may improve performance). Default is False. See tutorial_linalg_overwrite for details.

check_finite : bool, optional

Whether to check that the entire 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.

Returns

c : (..., M, M) ndarray

Matrix whose upper or lower triangle contains the Cholesky factor of a. Other parts of the matrix contain random data.

lower : ndarray, bool

Flag indicating whether the factor is in the lower or upper triangle

Raises

: LinAlgError

Raised if decomposition fails.

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. Consequently, if a is asymmetric/non-Hermitian, cholesky may still succeed if the symmetric/Hermitian matrix represented by the selected half is positive definite, yet it may fail if an element in the other half is non-finite.

Examples

import numpy as np
from scipy.linalg import cho_factor
A = np.array([[9, 3, 1, 5], [3, 7, 5, 1], [1, 5, 9, 2], [5, 1, 2, 6]],
            dtype=float, order="F")
A_ref = np.copy(A)
c, low = cho_factor(A)
✓
c
✗
array([[ 3.  ,  1.  ,  0.33,  1.67],
       [ 0.  ,  2.45,  1.91, -0.27],
       [ 0.  ,  0.  ,  2.29,  0.86],
       [ 0.  ,  0.  ,  0.  ,  1.55]])
np.allclose(c.T @ c - A, np.zeros((4, 4)))
c, low = cho_factor(A, overwrite_a=True)
✓
c
✗
array([[ 3.  ,  1.  ,  0.33,  1.67],
       [ 3.  ,  2.45,  1.91, -0.27],
       [ 1.  ,  5.  ,  2.29,  0.86],
       [ 5.  ,  1.  ,  2.  ,  1.55]])
np.allclose(np.triu(c).T @ np.triu(c) - A_ref, np.zeros((4, 4)))
✓
True

See also

cho_solve

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

cholesky

Compute the Cholesky decomposition and explicitly put the other triangle to 0.

Aliases

  • scipy.linalg.cho_factor

Referenced by