inverse_box

torch_sim.transforms.inverse_box(box)[source]

Compute the inverse of an affine transformation.

Computes the multiplicative inverse of a transformation, handling three cases: 1. Scalars: returns reciprocal (1/x) 2. Vectors: returns element-wise reciprocal 3. Matrices: returns matrix inverse using torch.linalg.inv

Parameters:

box (Tensor) – A PyTorch tensor representing either: - scalar: A single number (0-dim tensor or 1-element tensor) - vector: 1D tensor of scaling factors - matrix: 2D tensor representing linear transformation

Returns:

The inverse of the input transformation with the

same shape as input: - scalar -> scalar: 1/x - vector -> vector: element-wise 1/x - matrix -> matrix: matrix inverse

Return type:

Tensor

Raises:
  • ValueError – If the input tensor has more than 2 dimensions.

  • torch.linalg.LinAlgError – If matrix is singular (non-invertible).

Examples

>>> # Scalar inverse
>>> inverse_box(torch.tensor(2.0))
tensor(0.5000)
>>> # Vector inverse (element-wise)
>>> inverse_box(torch.tensor([2.0, 4.0]))
tensor([0.5000, 0.2500])
>>> # Matrix inverse
>>> mat = torch.tensor([[1.0, 2.0], [0.0, 1.0]])
>>> inverse_box(mat)
tensor([[ 1, -2],
        [ 0,  1]])