fn

cholesky_ex

Tensor
cholesky_ex(A: Tensor, upper: bool = False, check_errors: bool = False)
source

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 != 0 — numerical failure; LL is zero-filled.

Parameters

ATensor
Candidate SPD matrix of shape (*, n, n).
upper(bool, keyword - only)= False
If True return the upper-triangular factor UU such that A=UUA = U^\top U. Default False.
check_errors(bool, keyword - only)= False
If True, re-raise the underlying engine error instead of emitting a non-zero info — useful while debugging.

Returns

Tensor

Cholesky factor (or zeros on failure), shape (*, n, n).

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.

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