Skip to contents

Running maximum of array elements along a single dimension 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(operand, dim)

Arguments

operand

(arrayish)
Arrayish value of any data type.

dim

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

Value

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

Implemented Rules

  • stablehlo

  • reverse

StableHLO

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

See also

Examples

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