pose_format.torch.masked.tensor module
Classes:
|
Container for a PyTorch tensor, providing utility functions for tensor masking. |
- class pose_format.torch.masked.tensor.MaskedTensor(tensor, mask=None)[source]
Bases:
objectContainer 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 oftensorcorresponding toTruevalues in the mask are considered valid. Defaults to a tensor of allTruevalues.
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.
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
MaskedTensorafter the operation.- Return type:
- 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:
- 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:
- fix_nan()[source]
Replaces any NaN values in the tensor with zeros.
- Returns:
Tensor with NaN values replaced by zeros.
- Return type:
- matmul(matrix)[source]
Perform matrix multiplication.
- Parameters:
matrix (torch.Tensor) – matrix to multiply with.
- Returns:
New masked tensor after multiplication.
- Return type:
- permute(dims)[source]
Permute dimensions of tensor.
- Parameters:
dims (tuple) – Desired ordering of dimensions.
- Returns:
Permuted masked tensor.
- Return type:
- 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:
- rename(*names)[source]
Rename tensor’s dimensions.
- Parameters:
names (tuple) – Desired names for each dimension.
- Returns:
Renamed masked tensor.
- Return type:
- reshape(shape)[source]
Reshape tensor to given shape.
- Parameters:
shape (tuple) – Desired shape.
- Returns:
Reshaped tensor.
- Return type:
- 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:
- sum(dim)[source]
Sums along a specified dimension.
- Parameters:
dim (int) – dimension to sum over.
- Returns:
Summed tensor along the specified dimension.
- Return type:
- 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: