R/154_reductions_dcp2cone_canonicalizers_maximum_canon.R

Defines functions maximum_canon

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

## CVXPY SOURCE: reductions/eliminate_pwl/canonicalizers/maximum_canon.py
## max(x1, x2, ...) -> t where t >= xi for all i


maximum_canon <- function(expr, args, solver_context = NULL) {
  ## CVXPY wraps t with nonneg_wrap/nonpos_wrap to preserve sign.
  ## We achieve the same by creating t with appropriate Variable attributes.
  bounds <- get_expr_bounds_if_supported(expr, solver_context)
  t <- Variable(shape = .shape(expr),
                nonneg = is_nonneg(expr),
                nonpos = is_nonpos(expr),
                bounds = bounds)
  ## CVXPY maximum_canon: initialize the epigraph variable for DNLP use.
  if (!is.null(value(expr))) value(t) <- value(expr)
  constraints <- lapply(args, function(elem) t >= elem)
  list(t, constraints)
}

method(dcp_canonicalize, Maximum) <- maximum_canon
method(has_dcp_canon, Maximum) <- 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 Aug. 24, 2026, 9:10 a.m.