Skip to content
fn

cholesky_op

→TensorImplPtr
int cholesky_op(const int & a, bool upper)

Python wrappers

Public Python APIs implemented by this engine symbol.

Compute the Cholesky factor of a symmetric positive-definite matrix.

Returns the lower-triangular LL (default) or upper-triangular UU such that A=LL⊤A = LL^\top or A=U⊤UA = U^\top U respectively. Forward dispatches to LAPACK *potrf (CPU) or mlx::core::linalg::cholesky (GPU). Batched inputs are supported: every dimension except the trailing two is treated as a batch axis and the factorisation is run independently on each N×NN \times N slice.

Math

A=LL⊤orA=U⊤U. A = LL^\top \quad\text{or}\quad A = U^\top U.

The corresponding reverse-mode rule (Murray 2016) is

∂L∂A=12 L−⊤Φ ⁣(L⊤∂L∂L)L−1, \frac{\partial L}{\partial A} = \tfrac{1}{2}\, L^{-\top} \Phi\!\bigl(L^\top \tfrac{\partial L}{\partial L}\bigr) L^{-1},

where Φ(M)=tril(M)+tril(M,−1)⊤\Phi(M) = \mathrm{tril}(M) + \mathrm{tril}(M, -1)^\top copies the strict lower triangle into the strict upper. This formula is realised in the Python wrapper via two triangular solves, not in this engine op.

Shape

  • a: (..., N, N).
  • return: (..., N, N).

See Also

  • solve_triangular_op — triangular back/forward substitution used in the Python-side Cholesky backward.
  • ldl_factor_op — analogous factorisation for symmetric indefinite matrices.

Parameters

aTensorImplPtr
Square symmetric positive-definite matrix of shape (..., N, N), dtype F32 or F64.
upperbool= None
If true return the upper factor UU; otherwise (default) return the lower factor LL.

Returns

TensorImplPtr

Triangular Cholesky factor with the same shape and dtype as a. The opposite triangle is filled with zeros.

Raises

LucidError
If a is not at least 2-D, not square, or has a non-float dtype.
LucidError
If LAPACK info > 0 — a non-positive pivot was encountered, i.e. a is not positive definite (within working precision).

Notes

No autograd node is wired; the returned TensorImpl has requires_grad = false. Gradient-aware Cholesky is provided one layer up by lucid.linalg.cholesky.