R/140_reductions_dcp2cone_canonicalizers_cummax_canon.R

Defines functions cummax_canon

#####
## DO NOT EDIT THIS FILE!! EDIT THE SOURCE INSTEAD: rsrc_tree/reductions/dcp2cone/canonicalizers/cummax_canon.R
#####

## CVXPY SOURCE: reductions/eliminate_pwl/canonicalizers/cummax_canon.py
## cummax(X) -> Y where X <= Y, Y[k-1] <= Y[k]


cummax_canon <- function(expr, args, solver_context = NULL) {
  X <- args[[1L]]
  ax <- expr@axis
  Y <- Variable(shape = expr@shape)
  constr <- list(X <= Y)
  if (ax == 2L) {
    if (expr@shape[1L] == 1L) {
      return(list(X, list()))
    }
    constr <- c(constr, list(Y[1L:(expr@shape[1L] - 1L), ] <= Y[2L:expr@shape[1L], ]))
  } else {
    if (expr@shape[2L] == 1L) {
      return(list(X, list()))
    }
    constr <- c(constr, list(Y[, 1L:(expr@shape[2L] - 1L)] <= Y[, 2L:expr@shape[2L]]))
  }
  list(Y, constr)
}

method(dcp_canonicalize, Cummax) <- cummax_canon
method(has_dcp_canon, Cummax) <- function(expr) TRUE

Try the CVXR package in your browser

Any scripts or data that you put into this service are public.

CVXR documentation built on March 6, 2026, 9:10 a.m.