ml.utils.ops

Defines some functions to do specific common PyTorch operations.

ml.utils.ops.append_dims(x: Tensor, target_dims: int) Tensor[source]

Appends broadcastable dimensions to a given tensor.

Parameters:
  • x – The input tensor, with shape (*) and some number of dimensions smaller than target_dims

  • target_dims – The target number of dimensions, which should be larger than the number of dimensions of x

Returns:

A new tensor with shape (*, 1, ..., 1), with trailing ones added to make the tensor have target_dims dimensions.