Skip to main content

ClikaRT::ops::cast

function

cast()

Tensor cast(
    Tensor x,
    DataType target,
    bool force_copy = false
)

Same-device dtype conversion.

Converts per element to target. When x already has target's dtype and force_copy is false, the input passes through unchanged (no new storage); set force_copy = true to guarantee an owning copy.

Parameters

  • x: the input tensor.
  • target: the destination dtype.
  • force_copy: always materialize a new tensor. Default false.

Throws

  • ClikaRT::Error: when the input's dtype/shape is not served for this operation (the machine-readable reason rides code_name()).

Returns: x converted to target; same shape.

auto f32 = ClikaRT::ops::cast(t, ClikaRT::DataType::Float32);

Declared in ClikaRT/compute/ops.h, line 1970