Cast

Availability

Atlas Training Series Product

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, INT8, UINT8, INT16, UINT16, INT32, UINT32, INT64, UINT64, BOOL, COMPLEX64, or COMPLEX 128. The data format can be ND.

dstDtype

Input

Destination type of the converted tensor. The data type can be FLOAT16, FLOAT, DOUBLE, INT8, UINT8, INT16, UINT16, INT32, UINT32, INT64, UINT64, BOOL, COMPLEX64, or COMPLEX 128.

executor

Input

Operator executor, containing the operator computation process.

Returns

A tensor of dstDtype.

Constraints

None

Example

1
2
3
4
5
6
7
8
9
// (Fixed writing) Create 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 calculation.
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);
}