R/144_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.
  t <- Variable(shape = expr@shape,
                nonneg = is_nonneg(expr),
                nonpos = is_nonpos(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 March 6, 2026, 9:10 a.m.