Skip to content
fn

cholesky_ex

→Tensor
cholesky_ex(input: Tensor, upper: bool = False, check_errors: bool = False)

Cholesky factorization with an explicit success flag.

Variant of cholesky that, instead of raising when the input fails to be positive-definite, returns the factor together with an integer info code following LAPACK's convention:

  • info == 0 — success; LL (or UU) is meaningful.
  • info == k > 0 — the leading minor of order kk is not positive-definite; that matrix's factor holds only the part LAPACK defines, below.

Parameters

inputTensor
Candidate SPD matrix of shape (*, n, n).
upper(bool, keyword - only)= False
If True return the upper-triangular factor UU such that A=U⊤UA = U^\top U. Default False.
check_errors(bool, keyword - only)= False
If True, raise for the first matrix that fails instead of reporting it through info — useful while debugging.

Returns

Tensor

Cholesky factor of shape (*, n, n). For a matrix that failed at order kk, the leading (k−1)×(k−1)(k-1) \times (k-1) block is the factor of the minor that succeeded, the one part LAPACK defines; the rest is zero (LAPACK leaves it to its blocking).

Notes

Designed for code paths where a failed Cholesky is an expected event (e.g., trial steps in trust-region optimisers). Callers must inspect info before trusting L.

Each matrix of a batch is judged on its own: one failure leaves the other factors, and their gradients, intact. The batch is factorised once; only when that fails is each matrix tried alone, and a failed one bisected over its leading blocks to find the order LAPACK reports.

Examples

>>> import lucid
>>> from lucid.linalg import cholesky_ex
>>> A = lucid.tensor([[4.0, 2.0], [2.0, 3.0]])
>>> L, info = cholesky_ex(A)
>>> int(info)
0
>>> _, info = cholesky_ex(lucid.tensor([[1.0, 0.0], [0.0, -1.0]]))
>>> int(info)
2

Used by 1