---
title: "ClikaRT::ops::empty"
sidebar_label: "empty"
description: "Uninitialized tensor of the given shape; the contents are whatever the allocator hands back; write every element before reading any."
---

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

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

## empty() {#empty}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`empty`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ClikaRT::Span`](../Span.md)`<const` [`ScalarOrTensor`](../ScalarOrTensor.md)`>` `shape`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`DataType`](../../index.md#DataType) `dtype`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`StreamOrDevice`](../StreamOrDevice.md) `device` `=` `{}`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`StreamOrDevice`](../StreamOrDevice.md) `pinned_for` `=` `{}`<br />
)

</div>

Uninitialized tensor of the given shape; the contents are whatever the allocator hands back; write every element before reading any.

Each [`shape`](./shape.md#shape) extent is an int literal OR a 0-D integer [Tensor](../Tensor.md) (a tensor extent traces symbolically, never syncing to the host).

**Parameters**

- `shape`: the extents, one entry per dim.
- `dtype`: element type.
- `device`: stream or device to allocate on. Default: the default device.
- `pinned_for`: optional PEER device this allocation is pinned FOR: page-locked host memory the peer can DMA directly, so transfers to/from that peer skip staging. When set, [`device`](../device-namespace/index.md) must resolve to the CPU. Default: absent.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) when an extent is negative, or when `pinned_for` is set and [`device`](../device-namespace/index.md) is not the CPU (`code_name()` carries the reason).

**Returns:** a new tensor of shape [`shape`](./shape.md#shape); contents uninitialized.

```cpp
auto buf = ClikaRT::ops::empty({batch, dim}, ClikaRT::DataType::Float32);
```

<div class="api-declared">

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

</div>
