---
title: "ClikaRT::ops::chunk"
sidebar_label: "chunk"
description: "Split along dim into num_chunks near-equal parts (the last may be shorter). Returns VIEWS sharing the source's storage (one call, no copy); prefer it over repeated narrows."
---

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

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

## chunk() {#chunk}

<div class="api-signature">

`std::vector<`[`Tensor`](../Tensor.md)`>` **`chunk`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`int64_t` `num_chunks`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`int64_t` `dim` `=` `0`<br />
)

</div>

Split along `dim` into `num_chunks` near-equal parts (the last may be shorter). Returns VIEWS sharing the source's storage (one call, no copy); prefer it over repeated [`narrow`](./narrow.md#narrow)s.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) when `num_chunks` is not positive (`code_name()` carries the reason).

**Returns:** `num_chunks` views of the source.

```cpp
auto pair = ClikaRT::ops::chunk(gate_up, 2, -1);  // gate‖up split, no copy
```

<div class="api-declared">

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

</div>
