---
title: "ClikaRT::ops::copy"
sidebar_label: "copy"
description: "Copies a tensor, optionally to another device or stream. With the default force_copy = true the result always owns fresh storage; with force_copy = false a same-device copy may pass the input through.…"
---

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

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

## copy() {#copy}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`copy`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `src`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`StreamOrDevice`](../StreamOrDevice.md) `target` `=` `{}`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`bool` `force_copy` `=` `true`<br />
)

</div>

Copies a tensor, optionally to another device or stream.

With the default `force_copy = true` the result always owns fresh storage; with `force_copy = false` a same-device copy may pass the input through. `target` absent = `src`'s own stream.

**Parameters**

- `src`: the source tensor.
- `target`: destination stream or device. Default: stay put.
- `force_copy`: always materialize. Default `true`.

**Throws**

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

**Returns:** the copy, on `target`'s device; shape and dtype of `src`.

<div class="api-declared">

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

</div>
