---
title: "ClikaRT::ops::cumsum"
sidebar_label: "cumsum"
description: "Cumulative sum along dim (inclusive scan). \\[ \\mathrm{out}_k = \\sum_{j \\le k} x_j \\] Output mirrors input's shape; dtype widens the accumulation/output when set (Undefined keeps input's dtype)."
---

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

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

## cumsum() {#cumsum}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`cumsum`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`int64_t` `dim`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`DataType`](../../index.md#DataType) `dtype` `=` [`DataType::Undefined`](../../index.md#DataType)<br />
)

</div>

Cumulative sum along `dim` (inclusive scan).

$$
\mathrm{out}_k = \sum_{j \le k} x_j
$$

Output mirrors `input`'s shape; [`dtype`](../dtype/index.md) widens the accumulation/output when set (`Undefined` keeps `input`'s dtype).

**Parameters**

- `input`: the input tensor.
- `dim`: the axis to scan along.
- `dtype`: output dtype; `Undefined` keeps `input`'s dtype.

**Returns:** the scanned tensor, same shape as `input`.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) when `dim` is out of range.

```cpp
auto cu = ClikaRT::ops::cumsum(lengths, 0);   // prefix sums
```

<div class="api-declared">

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

</div>
