Skip to contents

Cumulative sum of array elements along a single dimension. Output position j along dim equals the sum of input positions 1:j.

Usage

prim_cumsum(operand, dim)

Arguments

operand

(arrayish)
Arrayish value of any data type.

dim

(integer(1))
Dimension along which to accumulate.

Value

arrayish
Has the same shape and data type as the input. It is ambiguous if the input is ambiguous.

Implemented Rules

  • stablehlo

  • reverse

StableHLO

Lowers to stablehlo::hlo_reduce_window() with stablehlo::hlo_add() as the reducer.

See also

Examples

x <- nv_matrix(1:6, nrow = 2)
prim_cumsum(x, dim = 1L)
#> AnvlArray
#>   1  3  5
#>   3  7 11
#> [ CPUi32{2,3} ]