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_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.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:

formatted string

kaolin.utils.testing.with_seed(torch_seed=0, numpy_seed=None, random_seed=None)

Decorator to fix the seed of a function.

Parameters:
  • torch_seed (int) – The desired seed for torch module.
  • random_seed (int) – The desired seed for random module. Default: torch_seed value.
  • numpy_seed (int) – The desired seed for numpy module. Default: torch_seed value.