cast
- Tensor.cast(dtype: Union[DataType, type], auto_cast: bool = True)
Creates a new tensor with the specified target data type, and optionally casts the data of original tensor with the target data type, stores casted data in the new tenor.
The new tensor is created with a contiguous memory layout in host memory. The new tensor does not contain any quantization information (QuantInfo).
Note
If
auto_castis set tofalse, the new tensor is created without storing any data. To store data from original Tensor object, setauto_casttotrue, which will automatically cast data to the target data type, and stores data in the new tensor.This function is only valid for non-image (multi-dimensional) tensors.
- Parameters:
dtype (Union[DataType, type]) -- The target data type for the new tensor. If a Python type, such as
np.float32is provided, it will be mapped to the corresponding internal DataType usingTensorInfo.numpy_tcim_map. SeeTensorInfofor details.auto_cast (bool) -- Specifies if to automatically cast the data of original Tensor object to the target data type specified in
dtype. If set totrue, the data will be automatically cast to the target data type withtcim_lite.runtime.Tensor.cast_to(), and stored in the new tensor. If set tofalse, the new tensor will be created with target data type without performing data casting. Defaults totrue.
- Returns:
A new object with the specified data type without quantization information.
- Return type:
- Raises:
RuntimeError -- If the operation fails, such as due to unsupported data type conversion or invalid tensor type (image tensor).