Skip to content
fn

cholesky

→Tensor
cholesky(input: Tensor, upper: bool = False)

Implementing kernel

C++ engine symbols that back this Python API.

Cholesky decomposition of a symmetric positive-definite matrix.

For a real symmetric positive-definite (SPD) matrix AA returns the unique lower-triangular factor LL with positive diagonal such that

A=LL⊤(or A=U⊤U if upper=True).A = L L^\top \qquad \text{(or } A = U^\top U \text{ if } \texttt{upper=True}\text{)}.

The Cholesky factor is the standard tool for solving SPD linear systems, sampling from a multivariate Gaussian, and computing matrix square roots. It is roughly twice as fast as LU and avoids any pivoting.

Parameters

inputTensor
Symmetric positive-definite matrix of shape (*, n, n).
upperbool= False
If True return the upper-triangular factor UU such that A=U⊤UA = U^\top U. Default False returns the lower-triangular factor LL.

Returns

Tensor

Triangular Cholesky factor of shape (*, n, n).

Notes

Algorithm: LAPACK potrf via Apple Accelerate on CPU, MLX on GPU. Cost is O(n3/3)O(n^3 / 3), half the work of LU.

Backward is implemented in Python via Murray's (2016) formula

∂L∂A = sym ⁣(L−⊤ Φ(L⊤G) L−1),\frac{\partial L}{\partial A} \,=\, \mathrm{sym}\!\big(L^{-\top}\,\Phi(L^\top G)\,L^{-1}\big),

where Φ\Phi zeros the strict upper triangle and halves the diagonal. Two triangular solves implement the inversion implicitly.

Examples

>>> import lucid
>>> from lucid.linalg import cholesky
>>> A = lucid.tensor([[4.0, 2.0], [2.0, 3.0]])  # SPD
>>> L = cholesky(A)
>>> L
tensor([[2., 0.], [1., 1.414]])
>>> L @ L.T
tensor([[4., 2.], [2., 3.]])

Used by 1