Cast - version 6#

This page documents version 6 of operator Cast. See Cast for the latest version (since version 28).

  • Domain: ai.onnx

  • Since version: 6

The operator casts the elements of a given input tensor to a data type specified by the ‘to’ argument and returns an output tensor of the same size in the converted type. The ‘to’ argument must be one of the data types specified in the ‘DataType’ enum field in the TensorProto message. NOTE: Casting to and from strings is not supported yet. The onnx-light native runtime additionally supports complex64 and complex128 as an extension to ONNX Cast. Real-to-complex casts set the imaginary component to zero. Complex-to-real casts discard it; complex precision casts preserve both components. Complex casts involving strings, float8 or packed types are unsupported. The standard ONNX schemas and full checker do not accept this extension.

Inputs

  • input (T1): Input tensor to be cast.

Outputs

  • output (T2): Output tensor with the same shape as input with type specified by the ‘to’ argument

Attributes

  • to (int): The data type to which the elements of the input tensor are cast. Strictly must be one of the types from DataType enum in TensorProto.

Type Constraints

  • T1: Constrain input types. Casting from strings is not supported. Complex types are an onnx-light runtime extension. Allowed types: tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8).

  • T2: Constrain output types. Casting to strings is not supported. Complex types are an onnx-light runtime extension. Allowed types: tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8).

Differences with previous version (1)#

SchemaDiff: Cast (domain 'ai.onnx')

  • old version: 1

  • new version: 6

  • breaking: yes

Breaking reasons:

  • attribute ‘to’ (changed): type changed STRING -> INT

Attributes:

  • [BREAKING] changed ‘to’: type changed STRING -> INT

Type constraints:

  • changed ‘T1’: added types: [‘tensor(complex128)’, ‘tensor(complex64)’]

  • changed ‘T2’: added types: [‘tensor(complex128)’, ‘tensor(complex64)’]

Documentation:

  • line similarity: 0.59 (+6/-1 lines)

--- Cast v1
+++ Cast v6
@@ -3,4 +3,9 @@
 specified by the 'to' argument and returns an output tensor of the same size in
 the converted type. The 'to' argument must be one of the data types specified
 in the 'DataType' enum field in the TensorProto message.
-NOTE: Casting to and from strings or complex types is not supported.
+NOTE: Casting to and from strings is not supported yet.
+The onnx-light native runtime additionally supports complex64 and complex128
+as an extension to ONNX Cast. Real-to-complex casts set the imaginary component
+to zero. Complex-to-real casts discard it; complex precision casts preserve both
+components. Complex casts involving strings, float8 or packed types are unsupported.
+The standard ONNX schemas and full checker do not accept this extension.