ConvertTo

Function Usage

Converts the value of a tensor to a specified type. Conversions between float32, float16, int8, int32, uint8, int16, uint16, uint32, int64, uint64, double64, and Boolean types are supported. Asynchronous calling is supported.

It is supported by the Atlas inference product and Atlas 200I/500 A2 inference product.

For the Atlas 200I/500 A2 inference product, preloading is supported (see Example of the Preloading File of the Initialization Operator).

The following conditions must be met:

Prototype

1
APP_ERROR ConvertTo(const Tensor &src, Tensor &dst, const MxBase::TensorDType &dataType, AscendStream& stream = AscendStream::DefaultStream());

Parameters

Parameter

Input/Output

Description

src

Input

Tensor class, input tensor.

  • For the inplace operation, the src ROI is the same as the dst shape.
  • For non-inplace operations, the shape of src is the same as that of dst.

dst

Output

Tensor class, output tensor. An empty tensor can be passed. If dst is not an empty tensor, call Tensor.Malloc() to allocate memory in advance.

dataType

Input

TensorDType class. It specifies the conversion type, which must be the same as the TensorDType property of dst.

stream

Input

AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the API calling is a synchronous operation. In other cases, the API calling is an asynchronous operation.

Response Parameters

Data Structure

Description

APP_ERROR

For details about the returned error codes, see APP_ERROR Description.