tf_quant_finance.utils.common_shape

Last updated: 2023-03-16.

tf_quant_finance.utils.common_shape#

View source

Returns common shape for a sequence of Tensors.

tf_quant_finance.utils.common_shape(
    *, name=None, *args
)

The common shape is the smallest-rank shape to which all tensors are broadcastable.

Example#

import tensorflow as tf
import tf_quant_finance as tff

args = [tf.ones([1, 2], dtype=tf.float64), tf.constant([[True], [False]])]
tff.utils.common_shape(*args)
# Expected: [2, 2]

Args:#

  • *args: A sequence of Tensors of compatible shapes and any dtypes.

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

Returns:#

A common shape for the input Tensors, which an instance of TensorShape, if the input shapes are fully defined, or a Tensor for dynamically shaped inputs.

Raises:#

  • ValueError: If inputs are of incompatible shapes.