solve_ex(A: Tensor, B: Tensor, left: bool = True, check_errors: bool = False)Solve with an explicit success flag.
Variant of solve that returns an info code instead of
raising on a singular coefficient matrix.
info == 0— success; is the unique solution.info == k > 0— of is exactly zero, so is singular; that system's is zero-filled.
Parameters
Coefficient matrix of shape
(*, n, n).Right-hand side of shape
(*, n, k) (or (*, n)).left(bool, keyword - only)= TrueCurrently must be
True. False (X A = B) is not yet
implemented and raises NotImplementedError.check_errors(bool, keyword - only)= FalseIf
True, raise for the first singular matrix instead of
reporting it through info.Returns
TensorSolution shaped like solve's — zeros for the systems whose
A was singular.
Notes
This is the recommended form when calling from inside a batched /
jit-compiled / vmapped routine where raising would break control
flow; manually inspect info afterwards and decide whether to
recover.
Each system of a batch is judged on its own: a singular A leaves
the other solutions, and their gradients, intact. The batch is solved
directly; only when that fails is A factorised again to find which
systems failed and at which pivot.
Examples
>>> import lucid
>>> from lucid.linalg import solve_ex
>>> A = lucid.tensor([[3.0, 1.0], [1.0, 2.0]])
>>> b = lucid.tensor([9.0, 8.0])
>>> X, info = solve_ex(A, b)
>>> int(info)
0