Constant - version 12#

This page documents version 12 of operator Constant. See Constant for the latest version (since version 25).

  • Domain: ai.onnx

  • Since version: 12

This operator produces a constant tensor. Exactly one of the provided attributes, either value, sparse_value, or value* must be specified.

Outputs

  • output (T): Output tensor containing the same value of the provided tensor.

Type Constraints

  • T: Constrain input and output types to all tensor types. Allowed types: 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_constant_value_float

Node:
  Constant() -> (y)
  Attributes:
    value_float = 3.5
Inputs:

Outputs:
  y: shape=(), dtype=float32
    3.5

test_cc_constant_value_floats

Node:
  Constant() -> (y)
  Attributes:
    value_floats = [1.0, 2.5, -3.25, 4.75]
Inputs:

Outputs:
  y: shape=(4,), dtype=float32
    [ 1.  ,  2.5 , -3.25,  4.75]

test_cc_constant_value_int

Node:
  Constant() -> (y)
  Attributes:
    value_int = 42
Inputs:

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

test_cc_constant_value_ints

Node:
  Constant() -> (y)
  Attributes:
    value_ints = [-1, 0, 1, 2, 3]
Inputs:

Outputs:
  y: shape=(5,), dtype=int64
    [-1,  0,  1,  2,  3]

test_cc_constant_value_string

Node:
  Constant() -> (y)
  Attributes:
    value_string = "hello"
Inputs:

Outputs:
  y: shape=(), dtype=object
    'hello'

test_cc_constant_value_strings

Node:
  Constant() -> (y)
  Attributes:
    value_strings = ['a', 'bc', 'def']
Inputs:

Outputs:
  y: shape=(3,), dtype=object
    ['a', 'bc', 'def']

Differences with previous version (11)#

SchemaDiff: Constant (domain 'ai.onnx')

  • old version: 11

  • new version: 12

  • breaking: no

Documentation:

  • line similarity: 0.33 (+2/-2 lines)

--- Constant v11
+++ Constant v12
@@ -1,3 +1,3 @@

-A constant tensor. Exactly one of the two attributes, either value or sparse_value,
-must be specified.
+This operator produces a constant tensor. Exactly one of the provided attributes, either value, sparse_value,
+or value_* must be specified.