Skip to contents

Running maximum of array elements along a single axis along with the index of the last occurrence of the running maximum. At output position j, the values output is max(input[1:j]) and the indices output is the largest i in 1:j with input[i] == values[j] (last-occurrence tiebreak).

Usage

prim_cummax(x, axis)

Arguments

x

(arrayish)
One input. Can be any data type. An R value materializes at its default 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

(named list of two arrayish)
Elements values, the running maximum at the input's data type, and indices, the running argmax at the default integer data type (see default_dtypes()). Both have the input's shape.

Implemented Rules

  • stablehlo

  • reverse

StableHLO

Lowers to hlo_reduce_window(), specified under reduce_window. The window is variadic over (values, iota), so the index of the running extremum is carried alongside it.

See also

Examples

# `values` keeps the input's data type, `indices` is the default integer
x <- nv_matrix(c(3, 1, 4, 1, 5, 9), nrow = 2)
prim_cummax(x, axis = 1L)
#> $values
#> AnvlArray
#>  3 4 5
#>  3 4 9
#> [ CPUf32{2,3} ] 
#> 
#> $indices
#> AnvlArray
#>  1 1 1
#>  1 1 2
#> [ CPUi32{2,3} ] 
#>