pose_format.torch.masked.tensor module

Classes:

MaskedTensor(tensor[, mask])

Container for a PyTorch tensor, providing utility functions for tensor masking.

class pose_format.torch.masked.tensor.MaskedTensor(tensor, mask=None)[source]

Bases: object

Container for a PyTorch tensor, providing utility functions for tensor masking.

Parameters:
  • tensor (torch.Tensor) – Tensor data.

  • mask (torch.Tensor, optional) – A boolean mask tensor of the same shape as tensor. If specified, elements of tensor corresponding to True values in the mask are considered valid. Defaults to a tensor of all True values.

Methods:

arithmetic(action, other)

Helper method to perform arithmetic operations on tensors.

cuda([device, non_blocking])

Moves tensor to the GPU.

div(other[, in_place, update_mask])

Performs element-wise division with another tensor.

fix_nan()

Replaces any NaN values in the tensor with zeros.

matmul(matrix)

Perform matrix multiplication.

permute(dims)

Permute dimensions of tensor.

pow_(exponent)

Raises tensor to power of a given exponent in-place.

rename(*names)

Rename tensor's dimensions.

reshape(shape)

Reshape tensor to given shape.

size(*args)

Get size of tensor for specified dimensions.

split(split_size_or_sections[, dim])

Split tensor into multiple tensors.

squeeze(dim)

Squeeze tensor along chosen dimension.

sum(dim)

Sums along a specified dimension.

to(device)

Moves tensor to a custom device.

transpose(dim0, dim1)

Transposes tensor along two dimensions.

zero_filled()

Get tensor with masked values set to zero.

arithmetic(action, other)[source]

Helper method to perform arithmetic operations on tensors.

Parameters:
  • action (str) – The arithmetic operation to be performed.

  • other (Union[MaskedTensor`, torch.Tensor, float, int]) – The second operand.

Returns:

New MaskedTensor after the operation.

Return type:

MaskedTensor

cuda(device=None, non_blocking=False)[source]

Moves tensor to the GPU.

Parameters:
  • device (str or torch.device, optional) – The target CUDA device.

  • non_blocking (bool, optional) – Whether to perform an operation asynchronously. Default is False.

Returns:

Tensor on CUDA device.

Return type:

MaskedTensor

div(other, in_place=False, update_mask=True)[source]

Performs element-wise division with another tensor.

Parameters:
  • other (MaskedTensor) – The tensor to divide with.

  • in_place (bool, optional) – If True, performs the operation in-place. Default is False.

  • update_mask (bool, optional) – If True, updates the mask after division. Default is True.

Returns:

Resultant tensor after division.

Return type:

MaskedTensor

fix_nan()[source]

Replaces any NaN values in the tensor with zeros.

Returns:

Tensor with NaN values replaced by zeros.

Return type:

MaskedTensor

matmul(matrix)[source]

Perform matrix multiplication.

Parameters:

matrix (torch.Tensor) – matrix to multiply with.

Returns:

New masked tensor after multiplication.

Return type:

MaskedTensor

permute(dims)[source]

Permute dimensions of tensor.

Parameters:

dims (tuple) – Desired ordering of dimensions.

Returns:

Permuted masked tensor.

Return type:

MaskedTensor

pow_(exponent)[source]

Raises tensor to power of a given exponent in-place.

Parameters:

exponent (float) – The exponent value.

Returns:

Masked tensor raised to a given exponent.

Return type:

MaskedTensor

rename(*names)[source]

Rename tensor’s dimensions.

Parameters:

names (tuple) – Desired names for each dimension.

Returns:

Renamed masked tensor.

Return type:

MaskedTensor

reshape(shape)[source]

Reshape tensor to given shape.

Parameters:

shape (tuple) – Desired shape.

Returns:

Reshaped tensor.

Return type:

MaskedTensor

size(*args)[source]

Get size of tensor for specified dimensions.

Returns:

Size of tensor.

Return type:

torch.Size

split(split_size_or_sections, dim=0)[source]

Split tensor into multiple tensors.

Parameters:
  • split_size_or_sections (int or tuple) – Size or sections to split tensor.

  • dim (int, optional) – Dimension along which to split tensor. Default is 0.

Returns:

List of split tensors.

Return type:

list[MaskedTensor]

squeeze(dim)[source]

Squeeze tensor along chosen dimension.

Parameters:

dim (int) – Dimension to squeeze.

Returns:

Squeezed masked tensor.

Return type:

MaskedTensor

sum(dim)[source]

Sums along a specified dimension.

Parameters:

dim (int) – dimension to sum over.

Returns:

Summed tensor along the specified dimension.

Return type:

MaskedTensor

to(device)[source]

Moves tensor to a custom device.

Parameters:

device (str or torch.device) – The target device.

Returns:

Tensor on the other device.

Return type:

MaskedTensor

transpose(dim0, dim1)[source]

Transposes tensor along two dimensions.

Parameters:
  • dim0 (int) – Two dimensions to which to transpose.

  • dim1 (int) – Two dimensions to which to transpose.

Returns:

Transposed masked tensor.

Return type:

MaskedTensor

zero_filled()[source]

Get tensor with masked values set to zero.

Returns:

Tensor with masked values set to zero.

Return type:

torch.Tensor