kaolin.utils.testing¶
API¶
- kaolin.utils.testing.check_packed_tensor(tensor, total_numel=None, last_dim=None, dtype=None, device=None, throw=True)¶
Check if packed tensor is valid given set of criteria.
- Parameters
tensor (torch.Tensor) – the packed tensor to be tested.
total_numel (int, optional) – the expected number of elements.
last_dim (int, optional) – the expected last dimension size.
dtype (torch.dtype, optional) – the expected dtype.
device (torch.device, optional) – the expected device.
throw (bool) – if True the check will raise an error if failing.
- Returns
status of the check.
- Return type
(bool)
- kaolin.utils.testing.check_padded_tensor(tensor, padding_value=None, shape_per_tensor=None, batch_size=None, max_shape=None, last_dim=None, dtype=None, device=None, throw=True)¶
Check if padded tensor is valid given set of criteria.
- Parameters
tensor (torch.Tensor) – the padded tensor to be tested.
padding_value (int, optional) – the expected number of elements,
shape_per_tensor
must be provided with padding_value.shape_per_tensor (torch.LongTensor, optional) – the expected
shape_per_tensor
.batch_size (int, optional) – the expected batch size.
last_dim (int, optional) – the expected last dimension size.
dtype (torch.dtype, optional) – the expected dtype.
device (torch.device, optional) – the expected device.
throw (bool) – if True the check will raise an error if failing.
- Returns
status of the check.
- Return type
(bool)
- kaolin.utils.testing.check_spc_octrees(octrees, lengths, batch_size=None, level=None, device=None, throw=True)¶
- kaolin.utils.testing.check_tensor(tensor, shape=None, dtype=None, device=None, throw=True)¶
Check if
torch.Tensor
is valid given set of criteria.- Parameters
tensor (torch.Tensor) – the tensor to be tested.
shape (list or tuple of int, optional) – the expected shape, if a dimension is set at
None
then it’s not verified.dtype (torch.dtype, optional) – the expected dtype.
device (torch.device, optional) – the expected device.
- kaolin.utils.testing.contained_torch_equal(elem, other)¶
Check for equality of two objects potentially containing tensors.
torch.equal()
do not support data structure like dictionary / arrays and == is ambiguous ontorch.Tensor
. This class will try to apply recursion throughcollections.abc.Mapping
,collections.abc.Sequence
,torch.equal()
if the objects are torch.Tensor, of else == operator.Return (bool): the comparison result
- kaolin.utils.testing.tensor_info(t, name='', print_stats=False, detailed=False)¶
Convenience method to format diagnostic tensor information, including shape, type, and optional attributes if specified as string. This information can then be logged as: logger.debug(tensor_info(my_tensor, ‘my tensor’))
Log output: my_tensor: [10, 2, 100, 100] (torch.float32)
- Parameters
t – input pytorch tensor or numpy array or None
name – human readable name of the tensor (optional)
print_stats – if True, includes mean/max/min statistics (takes compute time)
detailed – if True, includes details about tensor properties
- Returns
(String) formatted string
Examples
>>> t = torch.Tensor([0., 2., 3.]) >>> tensor_info(t, 'mytensor', True, True) 'mytensor: torch.Size([3]) (torch.float32) - [min 0.0000, max 3.0000, mean 1.6667] - req_grad=False, is_leaf=True, device=cpu, layout=torch.strided'
- kaolin.utils.testing.with_seed(torch_seed=0, numpy_seed=None, random_seed=None)¶
Decorator to fix the seed of a function.