fn
cholesky
→Tensorcholesky(x: Tensor, upper: bool = False)Cholesky decomposition of a symmetric positive-definite matrix.
For a real symmetric positive-definite (SPD) matrix returns the unique lower-triangular factor with positive diagonal such that
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
xTensorSymmetric positive-definite matrix of shape
(*, n, n).upperbool= FalseIf
True return the upper-triangular factor such
that . Default False returns the
lower-triangular factor .Returns
TensorTriangular Cholesky factor of shape (*, n, n).
Notes
Algorithm: LAPACK potrf via Apple Accelerate on CPU, MLX on GPU.
Cost is , half the work of LU.
Backward is implemented in Python via Murray's (2016) formula
where 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.0000, 0.0000],
[1.0000, 1.4142]])
>>> L @ L.T
Tensor([[4.0000, 2.0000],
[2.0000, 3.0000]])