R/149_reductions_dcp2cone_canonicalizers_sum_largest_canon.R

Defines functions sum_largest_canon

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

## CVXPY SOURCE: reductions/eliminate_pwl/canonicalizers/sum_largest_canon.py
## sum_largest(x, k) = min sum(t) + k*q s.t. x <= t + q, t >= 0


sum_largest_canon <- function(expr, args, solver_context = NULL) {
  x <- args[[1L]]
  k <- expr@k

  t <- Variable(shape = x@shape)
  q <- Variable(shape = c(1L, 1L))
  obj <- SumEntries(t) + as.numeric(k) * q
  constraints <- list(x <= t + cvxr_promote(q, x@shape), t >= 0)
  list(obj, constraints)
}

method(dcp_canonicalize, SumLargest) <- sum_largest_canon
method(has_dcp_canon, SumLargest) <- 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.