R/235_reductions_dnlp2smooth_canonicalizers_pnorm_canon.R

Defines functions .smooth_pnorm_canon

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

## CVXPY SOURCE: reductions/dnlp2smooth/canonicalizers/pnorm_canon.py
## 2-norm via quad_over_lin: ||x||_2 <= t  <=>  quad_over_lin(x, t) <= t.
## Only p = 2 is supported.

.smooth_pnorm_canon <- function(expr, args) {
  x <- args[[1L]]
  p <- expr@p
  shape <- .shape(expr)
  t <- Variable(shape, nonneg = TRUE)
  ## In DNLP the expression is expected to have a value; the check yields an
  ## informative error later if it does not.
  ev <- value(expr)
  if (!is.null(ev)) value(t) <- ev
  if (p == 2) {
    qol <- QuadOverLin(x, t)
    qol_res <- .smooth_quad_over_lin_canon(qol, .args(qol))
    list(t, c(qol_res[[2L]], list(qol_res[[1L]] <= t)))
  } else {
    cli_abort("Only {.code p = 2} is supported as {.cls Pnorm} in DNLP.")
  }
}

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.