docs/Broadcasting.md
In ONNX, element-wise operators can take inputs with different shape, as long as the input tensors are broadcastable to the same shape. ONNX supports two types of broadcasting: multidirectional broadcasting and unidirectional broadcasting. We will introduce these two types of broadcasting respectively in the following sections.
In ONNX, a set of tensors are multidirectional broadcastable to the same shape if one of the following is true:
For example, the following tensor shapes are supported by multidirectional broadcasting:
Multidirectional broadcasting is the same as Numpy's broadcasting.
Multidirectional broadcasting is supported by the following operators in ONNX:
In ONNX, tensor B is unidirectional broadcastable to tensor A if one of the following is true:
When unidirectional broadcasting happens, the output's shape is the same as the shape of A (i.e., the larger shape of two input tensors).
In the following examples, tensor B is unidirectional broadcastable to tensor A:
Unidirectional broadcasting is supported by the following operators in ONNX: