R/139_reductions_dcp2cone_canonicalizers_abs_canon.R

Defines functions abs_canon

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

## CVXPY SOURCE: reductions/eliminate_pwl/canonicalizers/abs_canon.py
## |x| -> t where t >= x, t >= -x


abs_canon <- function(expr, args, solver_context = NULL) {
  x <- args[[1L]]
  t <- Variable(shape = expr@shape)
  constraints <- list(t >= x, t >= -x)
  list(t, constraints)
}

method(dcp_canonicalize, Abs) <- abs_canon
method(has_dcp_canon, Abs) <- 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.