flopscope.

flopscope.numpy.linalg.cholesky

fnp.linalg.cholesky(a: 'ArrayLike', /, *, upper: 'bool' = False) -> 'FlopscopeArray'[flopscope source][numpy source]

Cholesky decomposition.

Adapted from NumPy docs np.linalg.cholesky

Arealinalg
Typecustom
Cost
n3n^3
Flopscope Context

Cholesky decomposition. Cost: $n^3$.

Return the lower or upper Cholesky decomposition, L * L.H or U.H * U, of the square matrix a, where L is lower-triangular, U is upper-triangular, and .H is the conjugate transpose operator (which is the ordinary transpose if a is real-valued). a must be Hermitian (symmetric if real-valued) and positive-definite. No checking is performed to verify whether a is Hermitian or not. In addition, only the lower or upper-triangular and diagonal elements of a are used. Only L or U is actually returned.

Parameters

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

Hermitian (symmetric if all elements are real), positive-definite input matrix.

upper:bool

If True, the result must be the upper-triangular Cholesky factor. If False, the result must be the lower-triangular Cholesky factor. Default: False.

Returns

L:(..., M, M) array_like

Lower or upper-triangular Cholesky factor of a. Returns a matrix object if a is a matrix object.

Raises

:LinAlgError

If the decomposition fails, for example, if a is not positive-definite.

See also

Notes

Broadcasting rules apply, see the flops.linalg documentation for details.

The Cholesky decomposition is often used as a fast way of solving

Ax=bA \mathbf{x} = \mathbf{b}

(when A is both Hermitian/symmetric and positive-definite).

First, we solve for y\mathbf{y} in

Ly=b,L \mathbf{y} = \mathbf{b},

and then for x\mathbf{x} in

LHx=y.L^{H} \mathbf{x} = \mathbf{y}.

Examples

>>> import flopscope.numpy as fnp
>>> A = flops.array([[1,-2j],[2j,5]])
>>> A
array([[ 1.+0.j, -0.-2.j],
       [ 0.+2.j,  5.+0.j]])
>>> L = flops.linalg.cholesky(A)
>>> L
array([[1.+0.j, 0.+0.j],
       [0.+2.j, 1.+0.j]])
>>> flops.dot(L, L.T.conj()) # verify that L * L.H = A
array([[1.+0.j, 0.-2.j],
       [0.+2.j, 5.+0.j]])
>>> A = [[1,-2j],[2j,5]] # what happens if A is only array_like?
>>> flops.linalg.cholesky(A) # an ndarray object is returned
array([[1.+0.j, 0.+0.j],
       [0.+2.j, 1.+0.j]])
>>> # But a matrix object is returned if A is a matrix object
>>> flops.linalg.cholesky(flops.matrix(A))
matrix([[ 1.+0.j,  0.+0.j],
        [ 0.+2.j,  1.+0.j]])
>>> # The upper-triangular Cholesky factor can also be obtained.
>>> flops.linalg.cholesky(A, upper=True)
array([[1.-0.j, 0.-2.j],
       [0.-0.j, 1.-0.j]])