R/236_reductions_dnlp2smooth_canonicalizers_geo_mean_canon.R

Defines functions .smooth_geo_mean_canon

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

## CVXPY SOURCE: reductions/dnlp2smooth/canonicalizers/geo_mean_canon.py
## geo_mean(x; w) via the log-domain: t >= 0, log(t) == sum(w .* log(x)).

.dnlp_geomean_MIN_INIT <- 1e-3

.smooth_geo_mean_canon <- function(expr, args) {
  t <- Variable(.shape(expr), nonneg = TRUE)
  v <- value(args[[1L]])
  if (!is.null(v)) {
    value(t) <- max(numeric_value(expr, list(v)), .dnlp_geomean_MIN_INIT)
  }
  weights <- as.numeric(expr@w)
  log_expr <- Log(args[[1L]])
  ## NOTE (matches CVXPY): log_canon is passed the ORIGINAL expr@args, not the
  ## already-canonicalized `args`.
  lc <- .smooth_log_canon(log_expr, .args(expr))
  var <- lc[[1L]]
  list(t, c(list(Log(t) == SumEntries(weights * var)), lc[[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.