Size - version 13#

This page documents version 13 of operator Size. See Size for the latest version (since version 25).

  • Domain: ai.onnx

  • Since version: 13

Takes a tensor as input and outputs a int64 scalar that equals to the total number of elements of the input tensor.

Inputs

  • data (T): An input tensor.

Outputs

  • size (T1): Total number of elements of the input tensor

Type Constraints

  • T: Input tensor can be of arbitrary type. 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).

  • T1: Constrain output to int64 tensor, which should be a scalar though. Allowed types: tensor(int64).

Examples#

test_cc_size

Node:
  Size(x) -> (y)
Inputs:
  x: shape=(3, 4, 5), dtype=float32
    [[[0., 0., 0., 0., 0.],
      [0., 0., 0., 0., 0.],
      [0., 0., 0., 0., 0.],
      [0., 0., 0., 0., 0.]],

     [[0., 0., 0., 0., 0.],
      [0., 0., 0., 0., 0.],
      [0., 0., 0., 0., 0.],
      [0., 0., 0., 0., 0.]],

     [[0., 0., 0., 0., 0.],
      [0., 0., 0., 0., 0.],
      [0., 0., 0., 0., 0.],
      [0., 0., 0., 0., 0.]]]

Outputs:
  y: shape=(), dtype=int64
    60

test_cc_size_empty

Node:
  Size(x) -> (y)
Inputs:
  x: shape=(2, 0, 3), dtype=float32
    []

Outputs:
  y: shape=(), dtype=int64
    0

test_cc_size_example

Node:
  Size(x) -> (y)
Inputs:
  x: shape=(2, 3), dtype=float32
    [[1., 2., 3.],
     [4., 5., 6.]]

Outputs:
  y: shape=(), dtype=int64
    6

test_cc_size_scalar

Node:
  Size(x) -> (y)
Inputs:
  x: shape=(), dtype=float32
    42.

Outputs:
  y: shape=(), dtype=int64
    1

Differences with previous version (1)#

SchemaDiff: Size (domain 'ai.onnx')

  • old version: 1

  • new version: 13

  • breaking: no

Type constraints:

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