Cast#
Cast - 13#
Version
name: Cast (GitHub)
domain: main
since_version: 13
function: False
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 13.
Summary
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.
Casting from string tensor in plain (e.g., “3.14” and “1000”) and scientific numeric representations (e.g., “1e-5” and “1E8”) to float types is supported. For example, converting string “100.5” to an integer may result 100. There are some string literals reserved for special floating-point values; “+INF” (and “INF”), “-INF”, and “NaN” are positive infinity, negative infinity, and not-a-number, respectively. Any string which can exactly match “+INF” in a case-insensitive way would be mapped to positive infinite. Similarly, this case-insensitive rule is applied to “INF” and “NaN”. When casting from numeric tensors to string tensors, plain floating-point representation (such as “314.15926”) would be used. Converting non-numerical-literal string such as “Hello World!” is an undefined behavior. Cases of converting string representing floating-point arithmetic value, such as “2.718”, to INT is an undefined behavior.
Conversion from a numerical type to any numerical type is always allowed. User must be aware of precision loss and value change caused by range difference between two types. For example, a 64-bit float 3.1415926459 may be round to a 32-bit float 3.141592. Similarly, converting an integer 36 to Boolean may produce 1 because we truncate bits which can’t be stored in the targeted type.
Attributes
to (required): 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
Inputs
input (heterogeneous) - T1: Input tensor to be cast.
Outputs
output (heterogeneous) - T2: Output tensor with the same shape as input with type specified by the ‘to’ argument
Type Constraints
T1 in ( tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain input types. Casting from complex is not supported.
T2 in ( tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain output types. Casting to complex is not supported.
Examples
Differences
0 | 0 | The operator casts the elements of a given input tensor to a data type | The operator casts the elements of a given input tensor to a data type |
1 | 1 | specified by the 'to' argument and returns an output tensor of the same size in | specified by the 'to' argument and returns an output tensor of the same size in |
2 | 2 | the converted type. The 'to' argument must be one of the data types specified | the converted type. The 'to' argument must be one of the data types specified |
3 | 3 | in the 'DataType' enum field in the TensorProto message. | in the 'DataType' enum field in the TensorProto message. |
4 | 4 |
|
|
5 | 5 | Casting from string tensor in plain (e.g., "3.14" and "1000") and scientific numeric representations | Casting from string tensor in plain (e.g., "3.14" and "1000") and scientific numeric representations |
6 | 6 | (e.g., "1e-5" and "1E8") to float types is supported. For example, converting string "100.5" to an integer may | (e.g., "1e-5" and "1E8") to float types is supported. For example, converting string "100.5" to an integer may |
7 | 7 | result 100. There are some string literals reserved for special floating-point values; | result 100. There are some string literals reserved for special floating-point values; |
8 | 8 | "+INF" (and "INF"), "-INF", and "NaN" are positive infinity, negative infinity, and not-a-number, respectively. | "+INF" (and "INF"), "-INF", and "NaN" are positive infinity, negative infinity, and not-a-number, respectively. |
9 | 9 | Any string which can exactly match "+INF" in a case-insensitive way would be mapped to positive infinite. Similarly, | Any string which can exactly match "+INF" in a case-insensitive way would be mapped to positive infinite. Similarly, |
10 | 10 | this case-insensitive rule is applied to "INF" and "NaN". When casting from numeric tensors | this case-insensitive rule is applied to "INF" and "NaN". When casting from numeric tensors |
11 | 11 | to string tensors, plain floating-point representation (such as "314.15926") would be used. | to string tensors, plain floating-point representation (such as "314.15926") would be used. |
12 | 12 | Converting non-numerical-literal string such as "Hello World!" is an undefined behavior. Cases | Converting non-numerical-literal string such as "Hello World!" is an undefined behavior. Cases |
13 | 13 | of converting string representing floating-point arithmetic value, such as "2.718", to INT is an undefined behavior. | of converting string representing floating-point arithmetic value, such as "2.718", to INT is an undefined behavior. |
14 | 14 |
|
|
15 | 15 | Conversion from a numerical type to any numerical type is always allowed. | Conversion from a numerical type to any numerical type is always allowed. |
16 | 16 | User must be aware of precision loss and value change caused by range difference between two types. | User must be aware of precision loss and value change caused by range difference between two types. |
17 | 17 | For example, a 64-bit float 3.1415926459 may be round to a 32-bit float 3.141592. Similarly, converting | For example, a 64-bit float 3.1415926459 may be round to a 32-bit float 3.141592. Similarly, converting |
18 | 18 | an integer 36 to Boolean may produce 1 because we truncate bits which can't be stored in the targeted type. | an integer 36 to Boolean may produce 1 because we truncate bits which can't be stored in the targeted type. |
19 | 19 |
|
|
20 | 20 | **Attributes** | **Attributes** |
21 | 21 |
|
|
22 | 22 | * **to** (required): | * **to** (required): |
23 | 23 | The data type to which the elements of the input tensor are cast. | The data type to which the elements of the input tensor are cast. |
24 | 24 | Strictly must be one of the types from DataType enum in TensorProto | Strictly must be one of the types from DataType enum in TensorProto |
25 | 25 |
|
|
26 | 26 | **Inputs** | **Inputs** |
27 | 27 |
|
|
28 | 28 | * **input** (heterogeneous) - **T1**: | * **input** (heterogeneous) - **T1**: |
29 | 29 | Input tensor to be cast. | Input tensor to be cast. |
30 | 30 |
|
|
31 | 31 | **Outputs** | **Outputs** |
32 | 32 |
|
|
33 | 33 | * **output** (heterogeneous) - **T2**: | * **output** (heterogeneous) - **T2**: |
34 | 34 | Output tensor with the same shape as input with type specified by | Output tensor with the same shape as input with type specified by |
35 | 35 | the 'to' argument | the 'to' argument |
36 | 36 |
|
|
37 | 37 | **Type Constraints** | **Type Constraints** |
38 | 38 |
|
|
39 | 39 | * **T1** in ( | * **T1** in ( |
40 | tensor(bfloat16), | ||
40 | 41 | tensor(bool), | tensor(bool), |
41 | 42 | tensor(double), | tensor(double), |
42 | 43 | tensor(float), | tensor(float), |
43 | 44 | tensor(float16), | tensor(float16), |
44 | 45 | tensor(int16), | tensor(int16), |
45 | 46 | tensor(int32), | tensor(int32), |
46 | 47 | tensor(int64), | tensor(int64), |
47 | 48 | tensor(int8), | tensor(int8), |
48 | 49 | tensor(string), | tensor(string), |
49 | 50 | tensor(uint16), | tensor(uint16), |
50 | 51 | tensor(uint32), | tensor(uint32), |
51 | 52 | tensor(uint64), | tensor(uint64), |
52 | 53 | tensor(uint8) | tensor(uint8) |
53 | 54 | ): | ): |
54 | 55 | Constrain input types. Casting from complex is not supported. | Constrain input types. Casting from complex is not supported. |
55 | 56 | * **T2** in ( | * **T2** in ( |
57 | tensor(bfloat16), | ||
56 | 58 | tensor(bool), | tensor(bool), |
57 | 59 | tensor(double), | tensor(double), |
58 | 60 | tensor(float), | tensor(float), |
59 | 61 | tensor(float16), | tensor(float16), |
60 | 62 | tensor(int16), | tensor(int16), |
61 | 63 | tensor(int32), | tensor(int32), |
62 | 64 | tensor(int64), | tensor(int64), |
63 | 65 | tensor(int8), | tensor(int8), |
64 | 66 | tensor(string), | tensor(string), |
65 | 67 | tensor(uint16), | tensor(uint16), |
66 | 68 | tensor(uint32), | tensor(uint32), |
67 | 69 | tensor(uint64), | tensor(uint64), |
68 | 70 | tensor(uint8) | tensor(uint8) |
69 | 71 | ): | ): |
70 | 72 | Constrain output types. Casting to complex is not supported. | Constrain output types. Casting to complex is not supported. |
Cast - 9#
Version
name: Cast (GitHub)
domain: main
since_version: 9
function: False
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 9.
Summary
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.
Casting from string tensor in plain (e.g., “3.14” and “1000”) and scientific numeric representations (e.g., “1e-5” and “1E8”) to float types is supported. For example, converting string “100.5” to an integer may result 100. There are some string literals reserved for special floating-point values; “+INF” (and “INF”), “-INF”, and “NaN” are positive infinity, negative infinity, and not-a-number, respectively. Any string which can exactly match “+INF” in a case-insensitive way would be mapped to positive infinite. Similarly, this case-insensitive rule is applied to “INF” and “NaN”. When casting from numeric tensors to string tensors, plain floating-point representation (such as “314.15926”) would be used. Converting non-numerical-literal string such as “Hello World!” is an undefined behavior. Cases of converting string representing floating-point arithmetic value, such as “2.718”, to INT is an undefined behavior.
Conversion from a numerical type to any numerical type is always allowed. User must be aware of precision loss and value change caused by range difference between two types. For example, a 64-bit float 3.1415926459 may be round to a 32-bit float 3.141592. Similarly, converting an integer 36 to Boolean may produce 1 because we truncate bits which can’t be stored in the targeted type.
Attributes
to (required): 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
Inputs
input (heterogeneous) - T1: Input tensor to be cast.
Outputs
output (heterogeneous) - T2: Output tensor with the same shape as input with type specified by the ‘to’ argument
Type Constraints
T1 in ( tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain input types. Casting from complex is not supported.
T2 in ( tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain output types. Casting to complex is not supported.
Differences
0 | 0 | The operator casts the elements of a given input tensor to a data type | The operator casts the elements of a given input tensor to a data type |
1 | 1 | specified by the 'to' argument and returns an output tensor of the same size in | specified by the 'to' argument and returns an output tensor of the same size in |
2 | 2 | the converted type. The 'to' argument must be one of the data types specified | the converted type. The 'to' argument must be one of the data types specified |
3 | 3 | in the 'DataType' enum field in the TensorProto message. | in the 'DataType' enum field in the TensorProto message. |
4 |
| ||
5 | Casting from string tensor in plain (e.g., "3.14" and "1000") and scientific numeric representations | ||
6 | (e.g., "1e-5" and "1E8") to float types is supported. For example, converting string "100.5" to an integer may | ||
7 | result 100. There are some string literals reserved for special floating-point values; | ||
8 | "+INF" (and "INF"), "-INF", and "NaN" are positive infinity, negative infinity, and not-a-number, respectively. | ||
4 | 9 | NOTE: Casting to and from strings is not supported yet. |
|
10 | this case-insensitive rule is applied to "INF" and "NaN". When casting from numeric tensors | ||
11 | to string tensors, plain floating-point representation (such as "314.15926") would be used. | ||
12 | Converting non-numerical-literal string such as "Hello World!" is an undefined behavior. Cases | ||
13 | of converting string representing floating-point arithmetic value, such as "2.718", to INT is an undefined behavior. | ||
5 | 14 |
|
|
15 | Conversion from a numerical type to any numerical type is always allowed. | ||
16 | User must be aware of precision loss and value change caused by range difference between two types. | ||
6 | 17 | **Attributes** |
|
18 | an integer 36 to Boolean may produce 1 because we truncate bits which can't be stored in the targeted type. | ||
7 | 19 |
|
|
20 | **Attributes** | ||
21 |
| ||
8 | 22 | * **to** (required): | * **to** (required): |
9 | 23 | The data type to which the elements of the input tensor are cast. | The data type to which the elements of the input tensor are cast. |
10 | 24 | Strictly must be one of the types from DataType enum in TensorProto | Strictly must be one of the types from DataType enum in TensorProto |
11 | 25 |
|
|
12 | 26 | **Inputs** | **Inputs** |
13 | 27 |
|
|
14 | 28 | * **input** (heterogeneous) - **T1**: | * **input** (heterogeneous) - **T1**: |
15 | 29 | Input tensor to be cast. | Input tensor to be cast. |
16 | 30 |
|
|
17 | 31 | **Outputs** | **Outputs** |
18 | 32 |
|
|
19 | 33 | * **output** (heterogeneous) - **T2**: | * **output** (heterogeneous) - **T2**: |
20 | 34 | Output tensor with the same shape as input with type specified by | Output tensor with the same shape as input with type specified by |
21 | 35 | the 'to' argument | the 'to' argument |
22 | 36 |
|
|
23 | 37 | **Type Constraints** | **Type Constraints** |
24 | 38 |
|
|
25 | 39 | * **T1** in ( | * **T1** in ( |
26 | 40 | tensor(bool), | tensor(bool), |
27 | 41 | tensor(double), | tensor(double), |
28 | 42 | tensor(float), | tensor(float), |
29 | 43 | tensor(float16), | tensor(float16), |
30 | 44 | tensor(int16), | tensor(int16), |
31 | 45 | tensor(int32), | tensor(int32), |
32 | 46 | tensor(int64), | tensor(int64), |
33 | 47 | tensor(int8), | tensor(int8), |
48 | tensor(string), | ||
34 | 49 | tensor(uint16), | tensor(uint16), |
35 | 50 | tensor(uint32), | tensor(uint32), |
36 | 51 | tensor(uint64), | tensor(uint64), |
37 | 52 | tensor(uint8) | tensor(uint8) |
38 | 53 | ): | ): |
39 | 54 | Constrain input types. Casting from strings and complex are not |
|
40 | supported. | ||
41 | 55 | * **T2** in ( | * **T2** in ( |
42 | 56 | tensor(bool), | tensor(bool), |
43 | 57 | tensor(double), | tensor(double), |
44 | 58 | tensor(float), | tensor(float), |
45 | 59 | tensor(float16), | tensor(float16), |
46 | 60 | tensor(int16), | tensor(int16), |
47 | 61 | tensor(int32), | tensor(int32), |
48 | 62 | tensor(int64), | tensor(int64), |
49 | 63 | tensor(int8), | tensor(int8), |
64 | tensor(string), | ||
50 | 65 | tensor(uint16), | tensor(uint16), |
51 | 66 | tensor(uint32), | tensor(uint32), |
52 | 67 | tensor(uint64), | tensor(uint64), |
53 | 68 | tensor(uint8) | tensor(uint8) |
54 | 69 | ): | ): |
55 | 70 | Constrain output types. Casting to strings and complex are not |
|
56 | supported. |
Cast - 6#
Version
name: Cast (GitHub)
domain: main
since_version: 6
function: False
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 6.
Summary
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.
Attributes
to (required): 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
Inputs
input (heterogeneous) - T1: Input tensor to be cast.
Outputs
output (heterogeneous) - T2: Output tensor with the same shape as input with type specified by the ‘to’ argument
Type Constraints
T1 in ( tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain input types. Casting from strings and complex are not supported.
T2 in ( tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain output types. Casting to strings and complex are not supported.
Differences
0 | 0 | The operator casts the elements of a given input tensor to a data type | The operator casts the elements of a given input tensor to a data type |
1 | 1 | specified by the 'to' argument and returns an output tensor of the same size in | specified by the 'to' argument and returns an output tensor of the same size in |
2 | 2 | the converted type. The 'to' argument must be one of the data types specified | the converted type. The 'to' argument must be one of the data types specified |
3 | 3 | in the 'DataType' enum field in the TensorProto message. | in the 'DataType' enum field in the TensorProto message. |
4 | 4 | NOTE: Casting to and from strings is not supported yet. | NOTE: Casting to and from strings is not supported yet. |
5 | 5 |
|
|
6 | 6 | **Attributes** | **Attributes** |
7 | 7 |
|
|
8 | 8 | * **to** (required): | * **to** (required): |
9 | 9 | The data type to which the elements of the input tensor are cast. | The data type to which the elements of the input tensor are cast. |
10 | 10 | Strictly must be one of the types from DataType enum in TensorProto | Strictly must be one of the types from DataType enum in TensorProto |
11 | 11 |
|
|
12 | 12 | **Inputs** | **Inputs** |
13 | 13 |
|
|
14 | 14 | * **input** (heterogeneous) - **T1**: | * **input** (heterogeneous) - **T1**: |
15 | 15 | Input tensor to be cast. | Input tensor to be cast. |
16 | 16 |
|
|
17 | 17 | **Outputs** | **Outputs** |
18 | 18 |
|
|
19 | 19 | * **output** (heterogeneous) - **T2**: | * **output** (heterogeneous) - **T2**: |
20 | 20 | Output tensor with the same shape as input with type specified by | Output tensor with the same shape as input with type specified by |
21 | 21 | the 'to' argument | the 'to' argument |
22 | 22 |
|
|
23 | 23 | **Type Constraints** | **Type Constraints** |
24 | 24 |
|
|
25 | 25 | * **T1** in ( | * **T1** in ( |
26 | 26 | tensor(bool), | tensor(bool), |
27 | 27 | tensor(double), | tensor(double), |
28 | 28 | tensor(float), | tensor(float), |
29 | 29 | tensor(float16), | tensor(float16), |
30 | 30 | tensor(int16), | tensor(int16), |
31 | 31 | tensor(int32), | tensor(int32), |
32 | 32 | tensor(int64), | tensor(int64), |
33 | 33 | tensor(int8), | tensor(int8), |
34 | 34 | tensor(uint16), | tensor(uint16), |
35 | 35 | tensor(uint32), | tensor(uint32), |
36 | 36 | tensor(uint64), | tensor(uint64), |
37 | 37 | tensor(uint8) | tensor(uint8) |
38 | 38 | ): | ): |
39 | 39 | Constrain input types. Casting from strings and complex are not | Constrain input types. Casting from strings and complex are not |
40 | 40 | supported. | supported. |
41 | 41 | * **T2** in ( | * **T2** in ( |
42 | 42 | tensor(bool), | tensor(bool), |
43 | 43 | tensor(double), | tensor(double), |
44 | 44 | tensor(float), | tensor(float), |
45 | 45 | tensor(float16), | tensor(float16), |
46 | 46 | tensor(int16), | tensor(int16), |
47 | 47 | tensor(int32), | tensor(int32), |
48 | 48 | tensor(int64), | tensor(int64), |
49 | 49 | tensor(int8), | tensor(int8), |
50 | 50 | tensor(uint16), | tensor(uint16), |
51 | 51 | tensor(uint32), | tensor(uint32), |
52 | 52 | tensor(uint64), | tensor(uint64), |
53 | 53 | tensor(uint8) | tensor(uint8) |
54 | 54 | ): | ): |
55 | 55 | Constrain output types. Casting to strings and complex are not | Constrain output types. Casting to strings and complex are not |
56 | 56 | supported. | supported. |
Cast - 1#
Version
name: Cast (GitHub)
domain: main
since_version: 1
function: False
support_level: SupportType.COMMON
shape inference: False
This version of the operator has been available since version 1.
Summary
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.
Attributes
to (required): 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
Inputs
input (heterogeneous) - T1: Input tensor to be cast.
Outputs
output (heterogeneous) - T2: Output tensor with the same shape as input with type specified by the ‘to’ argument
Type Constraints
T1 in ( tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain input types. Casting from strings and complex are not supported.
T2 in ( tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain output types. Casting to strings and complex are not supported.