cholesky_ex(A: 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; (or ) is meaningful.info == k > 0— the leading minor of order is not positive-definite; that matrix's factor holds only the part LAPACK defines, below.
Parameters
(*, n, n).upper(bool, keyword - only)= FalseTrue return the upper-triangular factor such
that . Default False.check_errors(bool, keyword - only)= FalseTrue, raise for the first matrix that fails instead of
reporting it through info — useful while debugging.Returns
TensorCholesky factor of shape (*, n, n). For a matrix that failed
at order , the leading 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