R/168_reductions_dcp2cone_canonicalizers_rel_entr_canon.R

Defines functions rel_entr_canon

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

## CVXPY SOURCE: reductions/dcp2cone/canonicalizers/rel_entr_canon.py
## rel_entr(x, y) = -t where ExpCone(t, x, y)


rel_entr_canon <- function(expr, args, solver_context = NULL) {
  shape <- expr@shape
  x <- cvxr_promote(args[[1L]], shape)
  y <- cvxr_promote(args[[2L]], shape)
  t <- Variable(shape = shape)
  constraints <- list(ExpCone(t, x, y))
  obj <- -t
  list(obj, constraints)
}

method(dcp_canonicalize, RelEntr) <- rel_entr_canon
method(has_dcp_canon, RelEntr) <- function(expr) TRUE

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.