The cumulative maximum, \(\max_{i=1,\ldots,k} x_i\) for \(k=1,\ldots,n\).
When calling cummax
, matrices are automatically flattened into column-major order before the max is taken.
cummax_axis(expr, axis = 2)
# S4 method for class 'Expression'
cummax(x)
(Optional) The dimension across which to apply the function: 1
indicates rows, and 2
indicates columns. The default is 2
.
An Expression, vector, or matrix.
val <- cbind(c(1,2), c(3,4))
value(cummax(Constant(val)))
#> [,1]
#> [1,] 1
#> [2,] 2
#> [3,] 3
#> [4,] 4
value(cummax_axis(Constant(val)))
#> [,1] [,2]
#> [1,] 1 3
#> [2,] 2 4
x <- Variable(2,2)
prob <- Problem(Minimize(cummax(x)[4]), list(x == val))
result <- solve(prob)
result$value
#> [1] 4
result$getValue(cummax(x))
#> [,1]
#> [1,] 1
#> [2,] 2
#> [3,] 3
#> [4,] 4