AffineMatrix#

class voxel.AffineMatrix(data=None, device=None, dtype=torch.float32)#

Affine matrix (4x4) transform for a 3D coordinate system.

property tensor: Tensor#

Tensor data of shape (4, 4).

save(filename, fmt=None) → None#

Save the affine matrix to a file.

Parameters:
  • filename (PathLike) – The path to the file to save.

  • fmt (str, optional) – The format of the file. If None, the format is determined by the file extension.

detach() → T#

Detach the matrix tensor from the current computational graph.

Returns:

A new affine with the detached matrix tensor.

to(device) → T#

Move the matrix tensor to a device.

Parameters:

device (device) – The target device.

Returns:

A new affine with the matrix tensor on the target device.

cuda() → T#

Move the matrix tensor to the GPU.

Returns:

A new affine with the matrix tensor on the GPU.

cpu() → T#

Move the matrix tensor to the CPU.

Returns:

A new affine with the matrix tensor on the CPU.

inverse() → AffineMatrix#

Invert the matrix. The inverse is computed in closed form through the 3x3 cofactors, so it never syncs with the host and can run inside a CUDA graph.

Returns:

AffineMatrix – Inverted affine matrix.

map(coords) → Tensor#

Map a set of 3D coordinates through the matrix transform.

Parameters:

coords (Tensor) – A tensor of coordinates with shape (…, 3).

Returns:

Tensor – Mapped coordinates with the same shape as the input.

transform(coords) → Tensor#

Deprecated alias of map.