Skip to contents

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

Usage

prim_cumsum(x, axis)

Arguments

x

(arrayish)
Arrayish value of any data type.

axis

(integer(1))
Axis along which to accumulate. Negative values count from the end, i.e. -1 refers to the last axis.

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 hlo_reduce_window() with hlo_add() as the reducer.

See also

Examples

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