Running minimum, optionally along a single dimension.
Arguments
- operand
(
arrayish)
Operand.- dim
(
integer(1)|NULL)
Dimension along which to accumulate. IfNULL(default), the input is first flattened to a 1-D array, likebase::cummin().- with_indices
(
logical(1))
IfFALSE(default), returns the running-minimum array. IfTRUE, returnslist(values = ..., indices = ...)whereindicesis the 1-based index of the last occurrence of the running minimum at each position (dtypei32, matching torch). Whendim = NULL, indices refer to the flattened input.- nan_rm
(
logical(1))
How to handleNaNvalues in floating-point 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 (when with_indices = FALSE) or named list of two
arrays (when with_indices = TRUE).
Relation to base R
Both nv_cummin() (with dim = NULL) and base::cummin()
flatten a multi-dimensional input to 1-D before accumulating, but the
flatten order differs: anvl arrays are row-major (C order), so the
flattened sequence iterates the last dim fastest, whereas base R uses
column-major (Fortran) order. The two agree on 1-D inputs.
See also
prim_cummin() for the underlying primitive.
Examples
x <- nv_matrix(c(3, 1, 4, 1, 5, 9), nrow = 2)
nv_cummin(x)
#> AnvlArray
#> 3
#> 3
#> 3
#> 1
#> 1
#> 1
#> [ CPUf32{6} ]
nv_cummin(x, dim = 1L)
#> AnvlArray
#> 3 4 5
#> 1 1 5
#> [ CPUf32{2,3} ]
nv_cummin(x, dim = 1L, with_indices = TRUE)
#> $values
#> AnvlArray
#> 3 4 5
#> 1 1 5
#> [ CPUf32{2,3} ]
#>
#> $indices
#> AnvlArray
#> 1 1 1
#> 2 2 1
#> [ CPUi32{2,3} ]
#>
nv_cummin(nv_array(c(3, NaN, 1))) # NaN propagates
#> AnvlArray
#> 3
#> nan
#> nan
#> [ CPUf32{3} ]
nv_cummin(nv_array(c(3, NaN, 1)), nan_rm = TRUE) # NaN skipped
#> AnvlArray
#> 3
#> 3
#> 1
#> [ CPUf32{3} ]