Last updated: 2023-03-16.

tf_quant_finance.math.pad.pad_tensors#

View source

Pads the innermost dimension of Tensors to a common shape.

tf_quant_finance.math.pad.pad_tensors(
    tensors, pad_values=None, dtype=None, name=None
)

Given a list of Tensors of the same dtype and with shapes batch_shape_i + [n_i], pads the innermost dimension of each tensor to batch_shape_i + [max(n_i)]. For each tensor t, the padding is done with values t[..., -1].

Example. Pad with the terminal value#

x = [[1, 2, 3, 9], [2, 3, 5, 2]]
y = [4, 5, 8]
pad_tensors([x, y])
# Expected: [array([[1, 2, 3, 9], [2, 3, 5, 2]], array([4, 5, 8, 8])]

Example. Pad with user-supplied values#

x = [[1, 2, 3, 9], [2, 3, 5, 2]]
y = [4, 5, 8]
pad_tensors([x, y], pad_values=10)
# Expected: [array([[1, 2, 3, 9], [2, 3, 5, 2]], array([4, 5, 8, 10])]

Args:#

  • tensors: A list of tensors of the same dtype and shapes batch_shape_i + [n_i].

  • pad_values: An optional scalar Tensor or a list of Tensors of shapes broadcastable with the corresponding batch_shape_i and the same dtype as pad_values. Corresponds to the padded values used for tensors.

  • dtype: The default dtype to use when converting values to Tensors. Default value: None which means that default dtypes inferred by TensorFlow are used.

  • name: Python string. The name to give to the ops created by this class. Default value: None which maps to the default name pad_tensors.

Returns:#

A list of Tensors of shape batch_shape_i + [max(n_i)].

Raises:#

  • ValueError: If input is not an instance of a list or a tuple.