CastLike#

  • Domain: ai.onnx

  • Since version: 25

The operator casts the elements of a given input tensor (the first input) to the same data type as the elements of the second input tensor. See documentation of the Cast operator for further details.

Inputs

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

  • target_type (T2): The (first) input tensor will be cast to produce a tensor of the same type as this (second input) tensor.

Outputs

  • output (T2): Output tensor produced by casting the first input tensor to have the same type as the second input tensor.

Type Constraints

  • T1: Constrain input types. Casting from complex is not supported. Allowed types: tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(float4e2m1), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz), tensor(float8e8m0), tensor(int16), tensor(int2), tensor(int32), tensor(int4), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint2), tensor(uint32), tensor(uint4), tensor(uint64), tensor(uint8).

  • T2: Constrain output types. Casting to complex is not supported. Allowed types: tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(float4e2m1), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz), tensor(float8e8m0), tensor(int16), tensor(int2), tensor(int32), tensor(int4), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint2), tensor(uint32), tensor(uint4), tensor(uint64), tensor(uint8).

Examples#

test_cc_castlike_FLOAT16_to_INT2

Node:
  CastLike(input, target_type) -> (output)
Inputs:
  input: shape=(7, 1), dtype=float16
    [[-3.],
     [-2.],
     [-1.],
     [ 0.],
     [ 1.],
     [ 2.],
     [ 3.]]
  target_type: shape=(1,), dtype=int2
    [0]

Outputs:
  output: shape=(7, 1), dtype=int2
    [[1],
     [-2],
     [-1],
     [0],
     [1],
     [-2],
     [-1]]

test_cc_castlike_FLOAT16_to_UINT2

Node:
  CastLike(input, target_type) -> (output)
Inputs:
  input: shape=(7, 1), dtype=float16
    [[-3.],
     [-2.],
     [-1.],
     [ 0.],
     [ 1.],
     [ 2.],
     [ 3.]]
  target_type: shape=(1,), dtype=uint2
    [0]

Outputs:
  output: shape=(7, 1), dtype=uint2
    [[1],
     [2],
     [3],
     [0],
     [1],
     [2],
     [3]]

test_cc_castlike_FLOAT_to_INT2

Node:
  CastLike(input, target_type) -> (output)
Inputs:
  input: shape=(7, 1), dtype=float32
    [[-3.],
     [-2.],
     [-1.],
     [ 0.],
     [ 1.],
     [ 2.],
     [ 3.]]
  target_type: shape=(1,), dtype=int2
    [0]

Outputs:
  output: shape=(7, 1), dtype=int2
    [[1],
     [-2],
     [-1],
     [0],
     [1],
     [-2],
     [-1]]

test_cc_castlike_FLOAT_to_UINT2

Node:
  CastLike(input, target_type) -> (output)
Inputs:
  input: shape=(7, 1), dtype=float32
    [[-3.],
     [-2.],
     [-1.],
     [ 0.],
     [ 1.],
     [ 2.],
     [ 3.]]
  target_type: shape=(1,), dtype=uint2
    [0]

Outputs:
  output: shape=(7, 1), dtype=uint2
    [[1],
     [2],
     [3],
     [0],
     [1],
     [2],
     [3]]

test_cc_castlike_INT2_to_FLOAT

Node:
  CastLike(input, target_type) -> (output)
Inputs:
  input: shape=(7, 1), dtype=int2
    [[1],
     [-2],
     [-1],
     [0],
     [1],
     [-2],
     [-1]]
  target_type: shape=(1,), dtype=float32
    [0.]

Outputs:
  output: shape=(7, 1), dtype=float32
    [[ 1.],
     [-2.],
     [-1.],
     [ 0.],
     [ 1.],
     [-2.],
     [-1.]]

test_cc_castlike_INT2_to_FLOAT16

Node:
  CastLike(input, target_type) -> (output)
Inputs:
  input: shape=(7, 1), dtype=int2
    [[1],
     [-2],
     [-1],
     [0],
     [1],
     [-2],
     [-1]]
  target_type: shape=(1,), dtype=float16
    [0.]

Outputs:
  output: shape=(7, 1), dtype=float16
    [[ 1.],
     [-2.],
     [-1.],
     [ 0.],
     [ 1.],
     [-2.],
     [-1.]]

test_cc_castlike_INT2_to_INT8

Node:
  CastLike(input, target_type) -> (output)
Inputs:
  input: shape=(7, 1), dtype=int2
    [[1],
     [-2],
     [-1],
     [0],
     [1],
     [-2],
     [-1]]
  target_type: shape=(1,), dtype=int8
    [0]

Outputs:
  output: shape=(7, 1), dtype=int8
    [[ 1],
     [-2],
     [-1],
     [ 0],
     [ 1],
     [-2],
     [-1]]

test_cc_castlike_UINT2_to_FLOAT

Node:
  CastLike(input, target_type) -> (output)
Inputs:
  input: shape=(7, 1), dtype=uint2
    [[1],
     [2],
     [3],
     [0],
     [1],
     [2],
     [3]]
  target_type: shape=(1,), dtype=float32
    [0.]

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

test_cc_castlike_UINT2_to_FLOAT16

Node:
  CastLike(input, target_type) -> (output)
Inputs:
  input: shape=(7, 1), dtype=uint2
    [[1],
     [2],
     [3],
     [0],
     [1],
     [2],
     [3]]
  target_type: shape=(1,), dtype=float16
    [0.]

Outputs:
  output: shape=(7, 1), dtype=float16
    [[1.],
     [2.],
     [3.],
     [0.],
     [1.],
     [2.],
     [3.]]

test_cc_castlike_UINT2_to_UINT8

Node:
  CastLike(input, target_type) -> (output)
Inputs:
  input: shape=(7, 1), dtype=uint2
    [[1],
     [2],
     [3],
     [0],
     [1],
     [2],
     [3]]
  target_type: shape=(1,), dtype=uint8
    [0]

Outputs:
  output: shape=(7, 1), dtype=uint8
    [[1],
     [2],
     [3],
     [0],
     [1],
     [2],
     [3]]

Differences with previous version (24)#

SchemaDiff: CastLike (domain 'ai.onnx')

  • old version: 24

  • new version: 25

  • breaking: no

Type constraints:

  • changed ‘T1’: added types: [‘tensor(int2)’, ‘tensor(uint2)’]

  • changed ‘T2’: added types: [‘tensor(int2)’, ‘tensor(uint2)’]

Version History#