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