trw.utils.batch_pad

Module Contents

Functions

batch_pad_numpy(array: trw.basic_typing.NumpyTensorNCX, padding: trw.basic_typing.ShapeCX, mode: str = 'edge', constant_value: trw.basic_typing.Numeric = 0)

Add padding on a numpy array of samples. This works for an arbitrary number of dimensions

batch_pad_torch(array: trw.basic_typing.TorchTensorNCX, padding: trw.basic_typing.ShapeCX, mode: str = 'edge', constant_value: trw.basic_typing.Numeric = 0)

Add padding on a numpy array of samples. This works for an arbitrary number of dimensions

batch_pad(array: trw.basic_typing.TensorNCX, padding: trw.basic_typing.ShapeCX, mode: str = 'edge', constant_value: trw.basic_typing.Numeric = 0)

Add padding on a numpy array of samples. This works for an arbitrary number of dimensions

batch_pad_joint(arrays: List[trw.basic_typing.TensorNCX], padding: trw.basic_typing.ShapeCX, mode: str = 'edge', constant_value: trw.basic_typing.Numeric = 0)

Add padding on a list of numpy or tensor array of samples. Supports arbitrary number of dimensions

trw.utils.batch_pad.batch_pad_numpy(array: trw.basic_typing.NumpyTensorNCX, padding: trw.basic_typing.ShapeCX, mode: str = 'edge', constant_value: trw.basic_typing.Numeric = 0)

Add padding on a numpy array of samples. This works for an arbitrary number of dimensions

Parameters
  • array – a numpy array. Samples are stored in the first dimension

  • padding – a sequence of size len(array.shape)-1 indicating the width of the padding to be added at the beginning and at the end of each dimension (except for dimension 0)

  • modenumpy.pad mode

  • constant_value – constant used if mode == constant

Returns

a padded array

trw.utils.batch_pad.batch_pad_torch(array: trw.basic_typing.TorchTensorNCX, padding: trw.basic_typing.ShapeCX, mode: str = 'edge', constant_value: trw.basic_typing.Numeric = 0)

Add padding on a numpy array of samples. This works for an arbitrary number of dimensions

This function mimics the API of transform_batch_pad_numpy so they can be easily interchanged.

Parameters
  • array – a Torch array. Samples are stored in the first dimension

  • padding – a sequence of size len(array.shape)-1 indicating the width of the padding to be added at the beginning and at the end of each dimension (except for dimension 0)

  • modenumpy.pad mode. Currently supported are (‘constant’, ‘edge’, ‘symmetric’)

  • constant_value – constant used if mode == constant

Returns

a padded array

trw.utils.batch_pad.batch_pad(array: trw.basic_typing.TensorNCX, padding: trw.basic_typing.ShapeCX, mode: str = 'edge', constant_value: trw.basic_typing.Numeric = 0)

Add padding on a numpy array of samples. This works for an arbitrary number of dimensions

Parameters
  • array – a numpy array. Samples are stored in the first dimension

  • padding – a sequence of size len(array.shape)-1 indicating the width of the padding to be added at the beginning and at the end of each dimension (except for dimension 0)

  • modenumpy.pad mode

  • constant_value – constant used if mode == constant

Returns

a padded array

trw.utils.batch_pad.batch_pad_joint(arrays: List[trw.basic_typing.TensorNCX], padding: trw.basic_typing.ShapeCX, mode: str = 'edge', constant_value: trw.basic_typing.Numeric = 0)

Add padding on a list of numpy or tensor array of samples. Supports arbitrary number of dimensions

Parameters
  • arrays – a numpy array. Samples are stored in the first dimension

  • padding – a sequence of size len(array.shape)-1 indicating the width of the padding to be added at the beginning and at the end of each dimension (except for dimension 0)

  • modenumpy.pad mode

  • constant_value – constant used if mode == constant

Returns

a list of padded arrays