Cast - 6 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.
- Cast6 → Cast13 +5 -37
Cast6 → 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
|
+
NOTE: Casting to and from strings is not supported yet.
|
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
|
-
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:
|
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.
|
36
6
|
**Attributes**
|
37
7
|
* **to** (required):
|
38
8
|
The data type to which the elements of the input tensor are cast.
|
39
9
|
Strictly must be one of the types from DataType enum in TensorProto
|
40
10
|
**Inputs**
|
41
11
|
* **input** (heterogeneous) - **T1**:
|
42
12
|
Input tensor to be cast.
|
43
13
|
**Outputs**
|
44
14
|
* **output** (heterogeneous) - **T2**:
|
45
15
|
Output tensor with the same shape as input with type specified by
|
46
16
|
the 'to' argument
|
47
17
|
**Type Constraints**
|
48
18
|
* **T1** in (
|
49
|
-
tensor(bfloat16),
|
50
19
|
tensor(bool),
|
51
20
|
tensor(double),
|
52
21
|
tensor(float),
|
53
22
|
tensor(float16),
|
54
23
|
tensor(int16),
|
55
24
|
tensor(int32),
|
56
25
|
tensor(int64),
|
57
26
|
tensor(int8),
|
58
|
-
tensor(string),
|
59
27
|
tensor(uint16),
|
60
28
|
tensor(uint32),
|
61
29
|
tensor(uint64),
|
62
30
|
tensor(uint8)
|
63
31
|
):
|
64
|
-
Constrain input types. Casting from complex
|
32
|
+
Constrain input types. Casting from strings and complex are not
|
33
|
+
supported.
|
65
34
|
* **T2** in (
|
66
|
-
tensor(bfloat16),
|
67
35
|
tensor(bool),
|
68
36
|
tensor(double),
|
69
37
|
tensor(float),
|
70
38
|
tensor(float16),
|
71
39
|
tensor(int16),
|
72
40
|
tensor(int32),
|
73
41
|
tensor(int64),
|
74
42
|
tensor(int8),
|
75
|
-
tensor(string),
|
76
43
|
tensor(uint16),
|
77
44
|
tensor(uint32),
|
78
45
|
tensor(uint64),
|
79
46
|
tensor(uint8)
|
80
47
|
):
|
81
|
-
Constrain output types. Casting to complex
|
48
|
+
Constrain output types. Casting to strings and complex are not
|
49
|
+
supported.
|