Cast - 1 vs 13¶
Next section compares an older to a newer version of the same operator after both definition are converted into markdown text. Green means an addition to the newer version, red means a deletion. Anything else is unchanged.
- Cast1 → Cast13 +36 -6
Cast1 → Cast13
RENAMED
@@ -1 +1 @@
|
|
1
1
|
The operator casts the elements of a given input tensor to a data type
|
2
2
|
specified by the 'to' argument and returns an output tensor of the same size in
|
3
3
|
the converted type. The 'to' argument must be one of the data types specified
|
4
4
|
in the 'DataType' enum field in the TensorProto message.
|
5
|
+
|
6
|
+
Casting from string tensor in plain (e.g., "3.14" and "1000") and scientific numeric representations
|
7
|
+
(e.g., "1e-5" and "1E8") to float types is supported. For example, converting string "100.5" to an integer may
|
8
|
+
yield result 100. There are some string literals reserved for special floating-point values;
|
9
|
+
"+INF" (and "INF"), "-INF", and "NaN" are positive infinity, negative infinity, and not-a-number, respectively.
|
10
|
+
Any string which can exactly match "+INF" in a case-insensitive way would be mapped to positive infinite. Similarly,
|
11
|
+
this case-insensitive rule is applied to "INF" and "NaN". When casting from numeric tensors
|
12
|
+
to string tensors, plain floating-point representation (such as "314.15926") would be used.
|
13
|
+
Converting non-numerical-literal string such as "Hello World!" is an undefined behavior. Cases
|
14
|
+
of converting string representing floating-point arithmetic value, such as "2.718", to INT is an undefined behavior.
|
15
|
+
|
16
|
+
Conversion from a numerical type to any numerical type is always allowed.
|
17
|
+
User must be aware of precision loss and value change caused by range difference between two types.
|
18
|
+
For example, a 64-bit float 3.1415926459 may be round to a 32-bit float 3.141592. Similarly, converting
|
19
|
+
an integer 36 to Boolean may produce 1 because we truncate bits which can't be stored in the targeted type.
|
20
|
+
|
21
|
+
In more detail, the conversion among numerical types should follow these rules:
|
22
|
+
|
23
|
+
* Casting from floating point to:
|
5
|
-
|
24
|
+
* floating point: +/- infinity if OOR (out of range).
|
25
|
+
* fixed point: undefined if OOR.
|
26
|
+
* bool: +/- 0.0 to False; all else to True.
|
27
|
+
* Casting from fixed point to:
|
28
|
+
* floating point: +/- infinity if OOR. (+ infinity in the case of uint)
|
29
|
+
* fixed point: when OOR, discard higher bits and reinterpret (with respect to two's complement representation for
|
30
|
+
signed types). For example, 200 (int16) -> -56 (int8).
|
31
|
+
* bool: zero to False; nonzero to True.
|
32
|
+
* Casting from bool to:
|
33
|
+
* floating point: {1.0, 0.0}.
|
34
|
+
* fixed point: {1, 0}.
|
35
|
+
* bool: no change.
|
6
36
|
### Attributes
|
7
|
-
* **to -
|
37
|
+
* **to - INT** (required) :
|
8
38
|
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
|
9
39
|
### Inputs
|
10
40
|
- **input** (heterogeneous) - **T1**:
|
11
41
|
Input tensor to be cast.
|
12
42
|
### Outputs
|
13
43
|
- **output** (heterogeneous) - **T2**:
|
14
44
|
Output tensor with the same shape as input with type specified by the 'to' argument
|
15
45
|
### Type Constraints
|
16
|
-
* **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) ):
|
46
|
+
* **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) ):
|
17
|
-
Constrain input types. Casting from
|
47
|
+
Constrain input types. Casting from complex is not supported.
|
18
|
-
* **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) ):
|
48
|
+
* **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) ):
|
19
|
-
Constrain output types. Casting to
|
49
|
+
Constrain output types. Casting to complex is not supported.? ^^
|