Mutual Derivation Relationship between Tensor and Scalar
Derivation Rules
When the input Tensor data type and the input Scalar data type of an API (such as aclnnAdds, aclnnMuls, etc.) are inconsistent, the API internally derives a data type and converts the input data to that data type for computation.
The type derivation rules are as follows:
NOTE
- For ease of description, the data types used in the table are abbreviated. Their meanings are: ACL_FLOAT(f32), ACL_FLOAT16(f16), ACL_DOUBLE(f64), ACL_BF16(bf16), ACL_INT8(s8), ACL_UINT8(u8), ACL_INT16(s16), ACL_UINT16(u16), ACL_INT32(s32), ACL_UINT32(u32), ACL_INT64(s64), ACL_UINT64(u64), ACL_BOOL(bool), ACL_COMPLEX32(c32), ACL_COMPLEX64(c64), ACL_COMPLEX128(c128).
- In the table, the header row represents the input Tensor data type to be derived, the leftmost column represents the input Scalar data type to be derived, and the corresponding cell in the table indicates the derived data type.
- A cross mark (x) in the table indicates that the two types cannot undergo derivation computation.
Table 1 Data type derivation relationship table
| Data Type | f32 | f16 | f64 | bf16 | s8 | u8 | s16 | u16 | s32 | u32 | s64 | u64 | bool | c32 | c64 | c128 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| f32 | f32 | f16 | f64 | bf16 | f32 | f32 | f32 | x | f32 | x | f32 | x | f32 | c32 | c64 | c128 |
| f16 | f32 | f16 | f64 | bf16 | f32 | f32 | f32 | x | f32 | x | f32 | x | f32 | c32 | c64 | c128 |
| f64 | f32 | f16 | f64 | bf16 | f32 | f32 | f32 | x | f32 | x | f32 | x | f32 | c128 | c128 | c128 |
| bf16 | f32 | f16 | f64 | bf16 | f32 | f32 | f32 | x | f32 | x | f32 | x | f32 | c32 | c64 | c128 |
| s8 | f32 | f16 | f64 | bf16 | s8 | u8 | s16 | u16 | s32 | u32 | s64 | u64 | s8 | c32 | c64 | c128 |
| u8 | f32 | f16 | f64 | bf16 | s8 | u8 | s16 | u16 | s32 | u32 | s64 | u64 | u8 | c32 | c64 | c128 |
| s16 | f32 | f16 | f64 | bf16 | s8 | u8 | s16 | u16 | s32 | u32 | s64 | u64 | s16 | c32 | c64 | c128 |
| u16 | f32 | f16 | f64 | bf16 | s8 | u8 | s16 | u16 | s32 | u32 | s64 | u64 | x | c32 | c64 | c128 |
| s32 | f32 | f16 | f64 | bf16 | s8 | u8 | s16 | u16 | s32 | u32 | s64 | u64 | s32 | c32 | c64 | c128 |
| u32 | f32 | f16 | f64 | bf16 | s8 | u8 | s16 | u16 | s32 | u32 | s64 | u64 | x | c32 | c64 | c128 |
| s64 | f32 | f16 | f64 | bf16 | s8 | u8 | s16 | u16 | s32 | u32 | s64 | u64 | s64 | c32 | c64 | c128 |
| u64 | f32 | f16 | f64 | bf16 | s8 | u8 | s16 | u16 | s32 | u32 | s64 | u64 | x | c32 | c64 | c128 |
| bool | f32 | f16 | f64 | bf16 | s8 | u8 | s16 | u16 | s32 | u32 | s64 | u64 | bool | c32 | c64 | c128 |
| c32 | c64 | c32 | c128 | c64 | c64 | c64 | c64 | c64 | c64 | c64 | c64 | c64 | c64 | c32 | c64 | c128 |
| c64 | c64 | c32 | c128 | c64 | c64 | c64 | c64 | c64 | c64 | c64 | c64 | c64 | c64 | c32 | c64 | c128 |
| c128 | c64 | c32 | c128 | c64 | c64 | c64 | c64 | c64 | c64 | c64 | c64 | c64 | c64 | c32 | c64 | c128 |
Derivation Examples
- If the data type of the input Tensor is float16 and the data type of the input Scalar is float32, the API internally converts the float32 data type of the input Scalar to float16 before performing the computation.
- If the data type of the input Tensor is bool and the data type of the input Scalar is float32, the API internally converts the bool data type of the input Tensor to float32 before performing the computation.