tensorinv

Contents

tensorinv#

class saiunit.linalg.tensorinv(a, ind=2, **kwargs)#

Compute the tensor inverse of an array.

SaiUnit implementation of numpy.linalg.tensorinv().

This computes the inverse of the tensordot() operation with the same ind value. The resulting unit is a.unit ** -1.

Parameters:
  • a (Array | ndarray | bool | number | bool | int | float | complex | saiunit.Quantity) – Quantity to be inverted. Must satisfy prod(a.shape[:ind]) == prod(a.shape[ind:]).

  • ind (int) – Positive integer specifying the number of indices in the tensor product (default: 2).

Returns:

out – Tensor inverse of shape (*a.shape[ind:], *a.shape[:ind]). The resulting unit is a.unit ** -1.

Return type:

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

See also

saiunit.linalg.tensorsolve

Solve the tensor equation a x = b.

saiunit.linalg.tensordot

Compute tensor dot product.

saiunit.linalg.inv

Compute the inverse of a square matrix.

Examples

>>> import saiunit as u
>>> import jax
>>> import jax.numpy as jnp
>>> key = jax.random.key(1337)
>>> x = jax.random.normal(key, shape=(2, 2, 4)) * u.second
>>> xinv = u.linalg.tensorinv(x, 2)
>>> xinv.shape
(4, 2, 2)
>>> xinv_x = u.linalg.tensordot(xinv, x, axes=2)
>>> u.math.allclose(xinv_x, jnp.eye(4), atol=1e-4)
Array(True, dtype=bool)