---
title: "ClikaRT::ops::flatten"
sidebar_label: "flatten"
description: "Collapse the INCLUSIVE dim range [start_dim, end_dim] into one dim; the defaults collapse everything to 1-D."
---

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

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

## flatten() {#flatten}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`flatten`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`int64_t` `start_dim` `=` `0`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`int64_t` `end_dim` `=` `-1`<br />
)

</div>

Collapse the INCLUSIVE dim range `[start_dim, end_dim]` into one dim; the defaults collapse everything to 1-D.

Returns a view sharing storage when the input's stride layout factors into the merged shape (contiguous inputs always do); copies into a fresh dense tensor otherwise.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) when the dim range is invalid (`code_name()` carries the reason).

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

```cpp
auto tokens = ClikaRT::ops::flatten(x, 0, 1);  // [B, S, D] -> [B*S, D]
```

<div class="api-declared">

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

</div>
