R/232_reductions_dnlp2smooth_canonicalizers_div_canon.R

Defines functions .smooth_div_canon

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

## CVXPY SOURCE: reductions/dnlp2smooth/canonicalizers/div_canon.py
## Canonicalize div(f(x), g(x)) as f(x) * power(z, -1), z = g(x), z >= 0.

.dnlp_div_MIN_INIT <- 1e-3

.smooth_div_canon <- function(expr, args) {
  if (!is_nonneg(args[[2L]])) {
    cli_warn(c(
      "CVXPY (DNLP) could not verify that the denominator of a division",
      "i" = "appearing in your problem is nonnegative. The solver will proceed",
      "i" = "under the assumption that the denominator is nonnegative. If this",
      "i" = "assumption is incorrect, the solution may be invalid."
    ))
  }
  z <- Variable(.shape(args[[2L]]), nonneg = TRUE)
  v <- value(args[[2L]])
  if (!is.null(v)) value(z) <- pmax(v, .dnlp_div_MIN_INIT)
  list(args[[1L]] * power(z, -1), list(z == args[[2L]]))
}

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.