scalar_conv
Description
Converts the data type of a Scalar.
The following conversion modes are supported:
- int32 to float32
- float32 to int32
- float32 to float16
- float16 to float32
Prototype
scalar_conv(round_mode, dst, src)
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
dst |
Output |
A Scalar of type float32/float16/int32, for the destination operand. |
round_mode |
Input |
Rounding mode
Table 2 describes the precision conversion and the corresponding round_mode. |
src |
Input |
Source operand. A Scalar of type float32/float16/int32. |
Applicability
Restrictions
Note the accuracy loss risks.
Value |
round |
floor |
ceil/ceiling |
away-zero |
to-zero |
odd |
|---|---|---|---|---|---|---|
1.8 |
2 |
1 |
2 |
2 |
1 |
2 |
1.5 |
2 |
1 |
2 |
2 |
1 |
1 |
1.2 |
1 |
1 |
2 |
2 |
1 |
1 |
0.8 |
1 |
0 |
1 |
1 |
0 |
1 |
0.5 |
0 |
0 |
1 |
1 |
0 |
1 |
0.2 |
0 |
0 |
1 |
1 |
0 |
0 |
-0.2 |
0 |
-1 |
0 |
-1 |
0 |
0 |
-0.5 |
0 |
-1 |
0 |
-1 |
0 |
-1 |
-0.8 |
-1 |
-1 |
0 |
-1 |
0 |
-1 |
-1.2 |
-1 |
-2 |
-1 |
-2 |
-1 |
-1 |
-1.5 |
-2 |
-2 |
-1 |
-2 |
-1 |
-1 |
-1.8 |
-2 |
-2 |
-1 |
-2 |
-1 |
2 |
Returns
None
Example
from tbe import tik tik_instance = tik.Tik() src_scalar = tik_instance.Scalar(dtype="float32") src_scalar.set_as(1.4) dst_scalar = tik_instance.Scalar(dtype="int32") round_mode = "ceiling" tik_instance.scalar_conv(round_mode, dst_scalar, src_scalar) """ round_mode=round dst_scalar=1 round_mode=away-zero dst_scalar=2 round_mode=to-zero dst_scalar=1 round_mode=floor dst_scalar=1 round_mode=ceil dst_scalar=2 round_mode=ceiling dst_scalar=2 """ tik_instance.BuildCCE(kernel_name="run_scalar_conv", inputs=[], outputs=[])