Running maximum, optionally along a single axis.
Arguments
- x
(
arrayish)
One input. Can be any data type. An R value materializes at its default data type.- axis
(
integer(1)|NULL)
Axis along which to accumulate. Negative values count from the end, i.e.-1refers to the last axis. IfNULL(default), the input is first flattened to a 1-D array, likebase::cummax().- indices
(
logical(1))
IfFALSE(default), returns the running-maximum array. IfTRUE, returnslist(values = ..., indices = ...)whereindicesis the index of the last occurrence of the running maximum at each position, of the default integer data type (seedefault_dtypes()). Whenaxis = NULL, indices refer to the flattened input.- nan_rm
(
logical(1))
How to handleNaNvalues in float inputs. IfFALSE(default),NaNpropagates forward from its first occurrence. IfTRUE,NaNis treated as the identity element of the cumulative op (0for sum,1for prod,-Inf/+Inffor max / min) and contributes nothing to the running value.
Value
(arrayish | named list of two arrayish)
One array when indices = FALSE, a named list of values and
indices when indices = TRUE. The values have the input's data
type and the indices the default integer data type; both have the input's shape when axis is
given, and are 1-D of length prod(shape(x)) when axis is NULL.
See also
prim_cummax() for the underlying primitive.
Examples
# the running maximum keeps the data type; the indices are the default integer
x <- nv_matrix(c(3, 1, 4, 1, 5, 9), nrow = 2)
nv_cummax(x)
#> AnvlArray
#> 3
#> 3
#> 4
#> 4
#> 5
#> 9
#> [ CPUf32{6} ]
nv_cummax(x, axis = 1L)
#> AnvlArray
#> 3 4 5
#> 3 4 9
#> [ CPUf32{2,3} ]
nv_cummax(x, axis = 1L, indices = TRUE)
#> $values
#> AnvlArray
#> 3 4 5
#> 3 4 9
#> [ CPUf32{2,3} ]
#>
#> $indices
#> AnvlArray
#> 1 1 1
#> 1 1 2
#> [ CPUi32{2,3} ]
#>
nv_cummax(nv_array(c(1, NaN, 3))) # NaN propagates
#> AnvlArray
#> 1
#> nan
#> nan
#> [ CPUf32{3} ]
nv_cummax(nv_array(c(1, NaN, 3)), nan_rm = TRUE) # NaN skipped
#> AnvlArray
#> 1
#> 1
#> 3
#> [ CPUf32{3} ]