R/218_reductions_dgp2dcp_canonicalizers_dgp_canonicalizers.R

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

## CVXPY SOURCE: reductions/dgp2dcp/canonicalizers/__init__.py
## DGP canonicalizer S7 method registrations
##
## Variable/Parameter handling is stateful (per-problem), done by dgp_methods closure.
## These method() registrations replace the old DGP_CANON_METHODS environment.

## -- S7 generic for DGP canonicalization ------------------------------
## Defined here (not in dgp2dcp.R) because this file loads before dgp2dcp.R
## and the method registrations below need the generic to exist.
## Default: NULL sentinel (no DGP canon for this class -> fall through to copy).
## Variable/Parameter dispatch remains in the tree walker (stateful closures).
##
## INHERITANCE SAFETY: Same invariant as dcp_canonicalize -- every subclass
## of a DGP-registered atom must have its own explicit method.

#' DGP canonicalization dispatch
#' @noRd
dgp_canonicalize <- new_generic("dgp_canonicalize", "expr",
  function(expr, args) {
    S7_dispatch()
  }
)

method(dgp_canonicalize, S7_object) <- function(expr, args) NULL

## Core Phase 1 canonicalizers
method(dgp_canonicalize, AddExpression)  <- .dgp_add_canon
method(dgp_canonicalize, Constant)       <- .dgp_constant_canon
method(dgp_canonicalize, DivExpression)  <- .dgp_div_canon
method(dgp_canonicalize, Multiply)       <- .dgp_mul_canon
method(dgp_canonicalize, MulExpression)  <- .dgp_mulexpression_canon
method(dgp_canonicalize, Power)          <- .dgp_power_canon
method(dgp_canonicalize, PowerApprox)    <- .dgp_power_canon
method(dgp_canonicalize, SumEntries)     <- .dgp_sum_canon
method(dgp_canonicalize, Exp)            <- .dgp_exp_canon
method(dgp_canonicalize, Log)            <- .dgp_log_canon
method(dgp_canonicalize, Trace)          <- .dgp_trace_canon

## Phase 2 canonicalizers (norms, geo_mean, quad forms, xexp)
method(dgp_canonicalize, Pnorm)          <- .dgp_pnorm_canon
method(dgp_canonicalize, PnormApprox)    <- .dgp_pnorm_canon
method(dgp_canonicalize, Norm1)          <- .dgp_norm1_canon
method(dgp_canonicalize, NormInf)        <- .dgp_norm_inf_canon
method(dgp_canonicalize, GeoMean)        <- .dgp_geo_mean_canon
method(dgp_canonicalize, GeoMeanApprox)  <- .dgp_geo_mean_canon
method(dgp_canonicalize, QuadForm)       <- .dgp_quad_form_canon
method(dgp_canonicalize, QuadOverLin)    <- .dgp_quad_over_lin_canon
method(dgp_canonicalize, Xexp)           <- .dgp_xexp_canon

## Phase 3 canonicalizers (DGP-specific atoms)
method(dgp_canonicalize, Prod)           <- .dgp_prod_canon
method(dgp_canonicalize, Cumprod)        <- .dgp_cumprod_canon
method(dgp_canonicalize, OneMInusPos)    <- .dgp_one_minus_pos_canon
method(dgp_canonicalize, EyeMinusInv)    <- .dgp_eye_minus_inv_canon
method(dgp_canonicalize, PfEigenvalue)   <- .dgp_pf_eigenvalue_canon
method(dgp_canonicalize, Gmatmul)        <- .dgp_gmatmul_canon

## PWL methods for max/min (matching CVXPY lines 102-105)
## These share the same canonicalizer functions as DCP (max_canon, min_canon, etc.)
## Wrappers needed: DCP canon fns have solver_context= but dgp_canonicalize has no ...
method(dgp_canonicalize, MaxEntries)     <- function(expr, args) max_canon(expr, args)
method(dgp_canonicalize, MinEntries)     <- function(expr, args) min_canon(expr, args)
method(dgp_canonicalize, Maximum)        <- function(expr, args) maximum_canon(expr, args)
method(dgp_canonicalize, Minimum)        <- function(expr, args) minimum_canon(expr, args)

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.