fn

inv_ex

Tensor
inv_ex(A: Tensor, check_errors: bool = False)
source

Matrix inverse with an explicit success flag.

Variant of inv that returns an info code instead of raising on a singular input.

  • info == 0 — success; Ainv is A1A^{-1}.
  • info != 0AA was singular; Ainv is zero-filled.

Parameters

ATensor
Square matrix of shape (*, n, n).
check_errors(bool, keyword - only)= False
If True, re-raise the underlying engine error instead of emitting a non-zero info.

Returns

Tensor

Inverse (or zero placeholder) of shape (*, n, n).

Notes

Useful in algorithms that occasionally probe near-singular matrices (e.g., iterative refinement, regularisation grid searches) without wanting to wrap every call in a try.

Examples

>>> import lucid
>>> from lucid.linalg import inv_ex
>>> Ainv, info = inv_ex(lucid.tensor([[1.0, 2.0], [3.0, 4.0]]))
>>> int(info)
0