Cast - 9 vs 13¶
- Cast9 → Cast13 +18 -0
Cast9 → 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
5
|
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
|
7
7
|
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.
|
9
9
|
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
|
11
11
|
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
|
13
13
|
of converting string representing floating-point arithmetic value, such as "2.718", to INT is an undefined behavior.
|
14
14
|
Conversion from a numerical type to any numerical type is always allowed.
|
15
15
|
User must be aware of precision loss and value change caused by range difference between two types.
|
16
16
|
For example, a 64-bit float 3.1415926459 may be round to a 32-bit float 3.141592. Similarly, converting
|
17
17
|
an integer 36 to Boolean may produce 1 because we truncate bits which can't be stored in the targeted type.
|
18
|
+
|
19
|
+
In more detail, the conversion among numerical types should follow these rules:
|
20
|
+
|
21
|
+
* Casting from floating point to:
|
22
|
+
* floating point: +/- infinity if OOR (out of range).
|
23
|
+
* fixed point: undefined if OOR.
|
24
|
+
* bool: +/- 0.0 to False; all else to True.
|
25
|
+
* Casting from fixed point to:
|
26
|
+
* floating point: +/- infinity if OOR. (+ infinity in the case of uint)
|
27
|
+
* fixed point: when OOR, discard higher bits and reinterpret (with respect to two's complement representation for
|
28
|
+
signed types). For example, 200 (int16) -> -56 (int8).
|
29
|
+
* bool: zero to False; nonzero to True.
|
30
|
+
* Casting from bool to:
|
31
|
+
* floating point: {1.0, 0.0}.
|
32
|
+
* fixed point: {1, 0}.
|
33
|
+
* bool: no change.
|
18
34
|
**Attributes**
|
19
35
|
* **to** (required):
|
20
36
|
The data type to which the elements of the input tensor are cast.
|
21
37
|
Strictly must be one of the types from DataType enum in TensorProto
|
22
38
|
**Inputs**
|
23
39
|
* **input** (heterogeneous) - **T1**:
|
24
40
|
Input tensor to be cast.
|
25
41
|
**Outputs**
|
26
42
|
* **output** (heterogeneous) - **T2**:
|
27
43
|
Output tensor with the same shape as input with type specified by
|
28
44
|
the 'to' argument
|
29
45
|
**Type Constraints**
|
30
46
|
* **T1** in (
|
47
|
+
tensor(bfloat16),
|
31
48
|
tensor(bool),
|
32
49
|
tensor(double),
|
33
50
|
tensor(float),
|
34
51
|
tensor(float16),
|
35
52
|
tensor(int16),
|
36
53
|
tensor(int32),
|
37
54
|
tensor(int64),
|
38
55
|
tensor(int8),
|
39
56
|
tensor(string),
|
40
57
|
tensor(uint16),
|
41
58
|
tensor(uint32),
|
42
59
|
tensor(uint64),
|
43
60
|
tensor(uint8)
|
44
61
|
):
|
45
62
|
Constrain input types. Casting from complex is not supported.
|
46
63
|
* **T2** in (
|
64
|
+
tensor(bfloat16),
|
47
65
|
tensor(bool),
|
48
66
|
tensor(double),
|
49
67
|
tensor(float),
|
50
68
|
tensor(float16),
|
51
69
|
tensor(int16),
|
52
70
|
tensor(int32),
|
53
71
|
tensor(int64),
|
54
72
|
tensor(int8),
|
55
73
|
tensor(string),
|
56
74
|
tensor(uint16),
|
57
75
|
tensor(uint32),
|
58
76
|
tensor(uint64),
|
59
77
|
tensor(uint8)
|
60
78
|
):
|
61
79
|
Constrain output types. Casting to complex is not supported.
|