Skip to contents

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

Usage

prim_cummin(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 minimum at the input's data type, and indices, the running argmin 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_cummin(x, axis = 1L)
#> $values
#> AnvlArray
#>  3 4 5
#>  1 1 5
#> [ CPUf32{2,3} ] 
#> 
#> $indices
#> AnvlArray
#>  1 1 1
#>  2 2 1
#> [ CPUi32{2,3} ] 
#>