R/241_reductions_dnlp2smooth_canonicalizers_smooth_canonicalizers.R

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

## CVXPY SOURCE: reductions/dnlp2smooth/canonicalizers/__init__.py
## DNLP (dnlp2smooth) canonicalizer S7 method registrations.
##
## CVXPY keys a SMOOTH_CANON_METHODS dict by atom class; CVXR dispatches via the
## smooth_canonicalize S7 generic (NULL default -> "no smooth canon for this
## class" -> the tree walker copies the node unchanged). Mirrors the dgp2dcp
## pattern in dgp_canonicalizers.R.
##
## Defined here (not in dnlp2smooth.R) because this file loads before
## dnlp2smooth.R and the registrations need the generic + canon functions.
##
## INHERITANCE SAFETY: as with dcp_canonicalize, every subclass of a registered
## atom needs its own explicit method (hence Power AND PowerApprox, etc.).

#' DNLP smooth-canonicalization dispatch
#' @noRd
smooth_canonicalize <- new_generic("smooth_canonicalize", "expr",
  function(expr, args) {
    S7_dispatch()
  }
)

## Default: NULL sentinel -> no smooth canon (tree walker falls through to copy).
method(smooth_canonicalize, S7_object) <- function(expr, args) NULL

# -- smooth elementwise atoms (full domain, chain rule in diff engine) -------
method(smooth_canonicalize, Exp)      <- .smooth_exp_canon
method(smooth_canonicalize, Logistic) <- .smooth_logistic_canon
method(smooth_canonicalize, Sin)      <- .smooth_sin_canon
method(smooth_canonicalize, Cos)      <- .smooth_cos_canon
method(smooth_canonicalize, Sinh)     <- .smooth_sinh_canon
method(smooth_canonicalize, Tanh)     <- .smooth_tanh_canon
method(smooth_canonicalize, Asinh)    <- .smooth_asinh_canon
method(smooth_canonicalize, Normcdf)  <- .smooth_normcdf_canon

# -- smooth atoms with nonnegative domain ------------------------------------
method(smooth_canonicalize, Log)  <- .smooth_log_canon
method(smooth_canonicalize, Entr) <- .smooth_entr_canon

# -- smooth atoms with bounded-interval domain -------------------------------
method(smooth_canonicalize, Tan)   <- .smooth_tan_canon
method(smooth_canonicalize, Atanh) <- .smooth_atanh_canon

# -- smooth atoms without chain rule yet (introduce equality copy) -----------
method(smooth_canonicalize, Prod) <- .smooth_prod_canon

# -- other smooth atoms with chain rule --------------------------------------
method(smooth_canonicalize, Multiply)      <- .smooth_multiply_canon
method(smooth_canonicalize, MulExpression) <- .smooth_matmul_canon
method(smooth_canonicalize, QuadForm)      <- .smooth_quad_form_canon

# -- dedicated smooth canonicalizers -----------------------------------------
method(smooth_canonicalize, QuadOverLin)   <- .smooth_quad_over_lin_canon
method(smooth_canonicalize, Power)         <- .smooth_power_canon
method(smooth_canonicalize, PowerApprox)   <- .smooth_power_canon
method(smooth_canonicalize, Pnorm)         <- .smooth_pnorm_canon
method(smooth_canonicalize, PnormApprox)   <- .smooth_pnorm_canon
method(smooth_canonicalize, DivExpression) <- .smooth_div_canon
method(smooth_canonicalize, RelEntr)       <- .smooth_rel_entr_canon
method(smooth_canonicalize, KlDiv)         <- .smooth_kl_div_canon
method(smooth_canonicalize, GeoMean)       <- .smooth_geo_mean_canon
method(smooth_canonicalize, GeoMeanApprox) <- .smooth_geo_mean_canon
method(smooth_canonicalize, LogSumExp)     <- .smooth_log_sum_exp_canon

# -- nonsmooth convex atom with a smooth epigraph (reuses abs canon) ---------
method(smooth_canonicalize, Huber) <- .smooth_huber_canon

# -- nonsmooth PWL atoms: reuse the dcp2cone (eliminate_pwl) canonicalizers ----
## CVXPY SOURCE: __init__.py:94-105 (imports abs/maximum/max/norm1/norm_inf/
## sum_largest/minimum/min canons from reductions.eliminate_pwl). These produce
## affine (linear) epigraph reformulations, which are smooth. The dcp2cone
## functions take an extra solver_context (unused here) so we wrap to the
## 2-argument smooth_canonicalize signature.

## nonsmooth convex atoms
method(smooth_canonicalize, Abs)        <- function(expr, args) abs_canon(expr, args)
method(smooth_canonicalize, Maximum)    <- function(expr, args) maximum_canon(expr, args)
method(smooth_canonicalize, MaxEntries) <- function(expr, args) max_canon(expr, args)
method(smooth_canonicalize, Norm1)      <- function(expr, args) norm1_canon(expr, args)
method(smooth_canonicalize, NormInf)    <- function(expr, args) norm_inf_canon(expr, args)
method(smooth_canonicalize, SumLargest) <- function(expr, args) sum_largest_canon(expr, args)

## nonsmooth concave atoms
method(smooth_canonicalize, Minimum)    <- function(expr, args) minimum_canon(expr, args)
method(smooth_canonicalize, MinEntries) <- function(expr, args) min_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 Aug. 24, 2026, 9:10 a.m.