---
title: "ClikaRT::ops::cast"
sidebar_label: "cast"
description: "Same-device dtype conversion. Converts per element to target. When input already has target's dtype and force_copy is false, the input passes through unchanged (no new storage); set force_copy = true…"
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--function">function</span>

## cast() {#cast}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`cast`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`DataType`](../../index.md#DataType) `target`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`bool` `force_copy` `=` `false`<br />
)

</div>

Same-device dtype conversion.

Converts per element to `target`. When `input` 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**

- `input`: 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:** `input` converted to `target`; same shape.

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

<div class="api-declared">

Declared in `ClikaRT/compute/ops.h`, line 2036

</div>
