pose_format.torch.masked package
pose_format.torch.masked subpackages:
- pose_format.torch.masked.tensor module
MaskedTensorMaskedTensor.arithmetic()MaskedTensor.cuda()MaskedTensor.div()MaskedTensor.fix_nan()MaskedTensor.matmul()MaskedTensor.permute()MaskedTensor.pow_()MaskedTensor.rename()MaskedTensor.reshape()MaskedTensor.size()MaskedTensor.split()MaskedTensor.squeeze()MaskedTensor.sum()MaskedTensor.to()MaskedTensor.transpose()MaskedTensor.zero_filled()
- pose_format.torch.masked.torch module
- pose_format.torch.masked.torch_test module
TestMaskedTorchTestMaskedTorch.test_cat()TestMaskedTorch.test_not_implemented_method()TestMaskedTorch.test_stack()TestMaskedTorch.test_zeros_mask_value()TestMaskedTorch.test_zeros_tensor_shape()TestMaskedTorch.test_zeros_tensor_type_bool()TestMaskedTorch.test_zeros_tensor_type_float()TestMaskedTorch.test_zeros_tensor_value()
pose_format.torch.masked.tensor module
- 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:
pose_format.torch.masked.torch module
Classes:
class mimicing torch functions and giving support for |
|
Meta class that gives a fallback mechanism to use torch functions on |
- class pose_format.torch.masked.torch.MaskedTorch[source]
Bases:
objectclass mimicing torch functions and giving support for
MaskedTensor.Methods:
cat(tensors, dim)Concatenate
MaskedTensorobjects along a specified dimension.squeeze(masked_tensor)Remove dimensions of size 1 from
MaskedTensor.stack(tensors, dim)Stack
MaskedTensorobjects along a new dimension.zeros(*size[, dtype])Creates a
MaskedTensorof zeros with a given shape and data type.- static cat(tensors, dim)[source]
Concatenate
MaskedTensorobjects along a specified dimension.- Parameters:
tensors (list) – List of tensors or
MaskedTensorobjects to be concatenated.dim (int) – Dimension along to concatenate.
- Returns:
Concatenated tensor.
- Return type:
- static squeeze(masked_tensor)[source]
Remove dimensions of size 1 from
MaskedTensor.- Parameters:
masked_tensor (
MaskedTensor) – tensor from which dimensions are to be removed.- Returns:
Squeezed masked tensor.
- Return type:
- static stack(tensors, dim)[source]
Stack
MaskedTensorobjects along a new dimension.- Parameters:
tensors (list) – List of
MaskedTensorobjects to be stacked.dim (int) – New dimension along which to stack.
- Returns:
Stacked maked tensor.
- Return type:
- static zeros(*size, dtype=None)[source]
Creates a
MaskedTensorof zeros with a given shape and data type.- Parameters:
*size (ints) – Dimensions of desired tensor.
dtype (torch.dtype, optional) – Data type of the tensor. If None, defaults to
torch.float.
- Returns:
masked tensor filled with zeros.
- Return type:
- class pose_format.torch.masked.torch.TorchFallback[source]
Bases:
typeMeta class that gives a fallback mechanism to use torch functions on
MaskedTensorobjects. :noindex:Attributes:
- doesnt_change_mask = {'acos', 'asin', 'atan', 'cos', 'sin', 'sqrt', 'square', 'tan', 'unsqueeze'}
pose_format.torch.masked.torch_test module
Classes:
|
Test cases for the |
- class pose_format.torch.masked.torch_test.TestMaskedTorch(methodName='runTest')[source]
Bases:
TestCaseTest cases for the
MaskedTensorclassMethods:
test_cat()Test
catmethod for concatenatingMaskedTensorobjects along a specified dimension.Tests behavior when invoking an unimplemented method on a
MaskedTensor.Tests
stackmethod for stackingMaskedTensorobjects along a new dimension.Test if the mask in the produced
zerosMaskedTensoris initialized with zero values.Test if
zerosmethod correctly produces aMaskedTensorwith the desired shape.Test if the
zerosmethod produces aMaskedTensorwith the correct boolean data type.Test if the
zerosmethod produces aMaskedTensorwith the correct float data type.Test if the
zerosmethod produces aMaskedTensorwith all zero values.- test_cat()[source]
Test
catmethod for concatenatingMaskedTensorobjects along a specified dimension.
- test_not_implemented_method()[source]
Tests behavior when invoking an unimplemented method on a
MaskedTensor.
- test_stack()[source]
Tests
stackmethod for stackingMaskedTensorobjects along a new dimension.
- test_zeros_mask_value()[source]
Test if the mask in the produced
zerosMaskedTensoris initialized with zero values.
- test_zeros_tensor_shape()[source]
Test if
zerosmethod correctly produces aMaskedTensorwith the desired shape.
- test_zeros_tensor_type_bool()[source]
Test if the
zerosmethod produces aMaskedTensorwith the correct boolean data type.
- test_zeros_tensor_type_float()[source]
Test if the
zerosmethod produces aMaskedTensorwith the correct float data type.
- test_zeros_tensor_value()[source]
Test if the
zerosmethod produces aMaskedTensorwith all zero values.