fn

solve_ex

Tensor
solve_ex(A: Tensor, B: Tensor, left: bool = True, check_errors: bool = False)
source

Solve AX=BAX = B with an explicit success flag.

Variant of solve that returns an info code instead of raising on a singular coefficient matrix.

  • info == 0 — success; XX is the unique solution.
  • info != 0AA was singular; XX is zero-filled.

Parameters

ATensor
Coefficient matrix of shape (*, n, n).
BTensor
Right-hand side of shape (*, n, k) (or (*, n)).
left(bool, keyword - only)= True
Currently must be True. False (X A = B) is not yet implemented and raises NotImplementedError.
check_errors(bool, keyword - only)= False
If True, re-raise the underlying engine error instead of emitting a non-zero info.

Returns

Tensor

Solution (or zero placeholder) shaped like B.

Notes

Implementation calls solve under the hood and converts the raised exception into the info flag. 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.

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