---
title: "ClikaRT::ops::unflatten"
sidebar_label: "unflatten"
description: "Split the dim at dim into sizes, the inverse of flatten. The product of sizes must equal that dim's extent. Returns a view sharing storage when the layout permits; copies otherwise."
---

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

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

## unflatten() {#unflatten}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`unflatten`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`int64_t` `dim`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ClikaRT::Span`](../Span.md)`<const std::int64_t>` `sizes`<br />
)

</div>

Split the dim at `dim` into `sizes`, the inverse of [`flatten`](./flatten.md#flatten). The product of `sizes` must equal that dim's extent.

Returns a view sharing storage when the layout permits; copies otherwise.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) when the product of `sizes` mismatches the dim's extent (`code_name()` carries the reason).

**Returns:** the reshaped tensor, a view when the layout permits.

```cpp
auto heads = ClikaRT::ops::unflatten(x, -1, {n_heads, head_dim});
```

<div class="api-declared">

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

</div>
