fn

cumsum

Tensor
cumsum(input: Tensor, dim: DimLike = ...)
source

Return the cumulative sum of elements along dim.

The i-th output along dim is the sum of all input values at positions 0..i inclusive. Useful for computing running totals, integration on discrete grids, and constructing offset/index buffers.

Parameters

inputTensor
Source tensor.
dimDimLike= ...
Dimension along which to accumulate.

Returns

Tensor

Same shape and dtype as input.

Notes

yi  =  k=0ixk.y_i \;=\; \sum_{k=0}^{i} x_k .

Floating-point accumulation is performed left-to-right with naive summation — for very long inputs a Kahan-compensated reduction may yield smaller error but is not used here for performance reasons.

Examples

>>> import lucid
>>> x = lucid.tensor([1.0, 2.0, 3.0, 4.0])
>>> lucid.cumsum(x, dim=0)
Tensor([ 1.,  3.,  6., 10.])