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)
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

list of two arrayish values:
The running maximum (same dtype as x) and the running argmax (dtype i32, 1-based). Both have the same shape as x.

Implemented Rules

  • stablehlo

  • reverse

StableHLO

Lowers to a variadic hlo_reduce_window() over (values, iota).

See also

Examples

x <- nv_matrix(c(3, 1, 4, 1, 5, 9), nrow = 2)
prim_cummax(x, axis = 1L)
#> [[1]]
#> AnvlArray
#>  3 4 5
#>  3 4 9
#> [ CPUf32{2,3} ] 
#> 
#> [[2]]
#> AnvlArray
#>  1 1 1
#>  1 1 2
#> [ CPUi32{2,3} ] 
#>