Expand#

  • Domain: ai.onnx

  • Since version: 13

Broadcast the input tensor following the given shape and the broadcast rule. The broadcast rule is similar to numpy.array(input) * numpy.ones(shape): Dimensions are right alignment; Two corresponding dimensions must have the same value, or one of them is equal to 1. Also, this operator is similar to numpy.broadcast_to(input, shape), but the major difference is numpy.broadcast_to() does not allow shape to be smaller than input.size(). It is possible that the output.shape is not equal to shape, when some dimensions in shape is equal to 1, or the shape.ndim < input.shape.ndim.

Inputs

  • input (T): Input tensor

  • shape (tensor(int64)): A 1-D tensor indicates the shape you want to expand to, following the broadcast rule

Outputs

  • output (T): Output tensor

Type Constraints

  • T: Constrain input and output types to all tensors. Allowed types: tensor(bfloat16), tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8).

Examples#

test_cc_expand_1d_to_2d

Node:
  Expand(input, shape) -> (output)
Inputs:
  input: shape=(4,), dtype=float32
    [1., 2., 3., 4.]
  shape: shape=(2,), dtype=int64
    [3, 4]

Outputs:
  output: shape=(3, 4), dtype=float32
    [[1., 2., 3., 4.],
     [1., 2., 3., 4.],
     [1., 2., 3., 4.]]

test_cc_expand_dim_changed

Node:
  Expand(input, shape) -> (output)
Inputs:
  input: shape=(3, 1), dtype=float32
    [[1.],
     [2.],
     [3.]]
  shape: shape=(3,), dtype=int64
    [2, 3, 6]

Outputs:
  output: shape=(2, 3, 6), dtype=float32
    [[[1., 1., 1., 1., 1., 1.],
      [2., 2., 2., 2., 2., 2.],
      [3., 3., 3., 3., 3., 3.]],

     [[1., 1., 1., 1., 1., 1.],
      [2., 2., 2., 2., 2., 2.],
      [3., 3., 3., 3., 3., 3.]]]

test_cc_expand_dim_unchanged

Node:
  Expand(input, shape) -> (output)
Inputs:
  input: shape=(3, 1), dtype=float32
    [[1.],
     [2.],
     [3.]]
  shape: shape=(2,), dtype=int64
    [3, 4]

Outputs:
  output: shape=(3, 4), dtype=float32
    [[1., 1., 1., 1.],
     [2., 2., 2., 2.],
     [3., 3., 3., 3.]]

Differences with previous version (8)#

SchemaDiff: Expand (domain 'ai.onnx')

  • old version: 8

  • new version: 13

  • breaking: no

Type constraints:

  • changed ‘T’: added types: [‘tensor(bfloat16)’]

Version History#