inv

Contents

inv#

class brainunit.linalg.inv(a, **kwargs)#

Return the inverse of a square matrix.

SaiUnit implementation of numpy.linalg.inv().

The resulting unit is a.unit ** -1.

Parameters:

a (Array | ndarray | bool | number | bool | int | float | complex | saiunit.Quantity) – Square input of shape (..., N, N) specifying square matrix(es) to be inverted.

Returns:

out – Inverse matrix of shape (..., N, N). The resulting unit is a.unit ** -1.

Return type:

Array | ndarray | bool | number | bool | int | float | complex | saiunit.Quantity

See also

saiunit.linalg.solve

Solve a linear system (preferred over explicit inverse).

saiunit.linalg.pinv

Compute the Moore-Penrose pseudo-inverse.

Notes

In most cases, explicitly computing the inverse of a matrix is ill-advised. For example, to compute x = inv(A) @ b, it is more performant and numerically precise to use a direct solve, such as saiunit.linalg.solve().

Examples

>>> import saiunit as u
>>> import jax.numpy as jnp
>>> a = jnp.array([[1., 2., 3.],
...                [2., 4., 2.],
...                [3., 2., 1.]]) * u.second
>>> a_inv = u.linalg.inv(a)
>>> u.math.allclose(a @ a_inv, jnp.eye(3), atol=1e-5)
Array(True, dtype=bool)