Cast
Applicability
Product |
Supported |
|---|---|
√ |
|
√ |
|
x |
|
√ |
|
√ |
Function Usage
Converts an input tensor to the specified data type.
Prototype
const aclTensor *Cast(const aclTensor *self, op::DataType dstDtype, aclOpExecutor *executor)
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
self |
Input |
Input tensor to be converted. The data type can be FLOAT16, FLOAT, DOUBLE, BFLOAT16, INT8, UINT8, INT16, UINT16, INT32, UINT32, INT64, UINT64, BOOL, COMPLEX64, or COMPLEX 128. The data format can be ND. NOTE:
BFLOAT16 applies to the following product models: |
dstDtype |
Input |
Destination type of the converted tensor. The data type can be FLOAT16, FLOAT, DOUBLE, BFLOAT16, INT8, UINT8, INT16, UINT16, INT32, UINT32, INT64, UINT64, BOOL, COMPLEX64, or COMPLEX 128. NOTE:
BFLOAT16 applies to the following product models: |
executor |
Input |
Operator executor, containing the operator computation process. |
Returns
A tensor of dstDtype.
Constraints
None
Examples
1 2 3 4 5 6 7 8 9 | // Standard format for creating an OpExecutor auto uniqueExecutor = CREATE_EXECUTOR(); auto selfCasted = self; // When self is of the Boolean type, use the Cast API to convert it to the uint8 type for integer computation. if (self->GetDataType() == op::DataType::DT_BOOL) { selfCasted = l0op::Cast(self, op::DataType::DT_UINT8, uniqueExecutor.get()); CHECK_RET(selfCasted != nullptr, ACLNN_ERR_PARAM_NULLPTR); } |