R/194_reductions_dgp2dcp_util.R

Defines functions .dgp_explicit_sum

#####
## DO NOT EDIT THIS FILE!! EDIT THE SOURCE INSTEAD: rsrc_tree/reductions/dgp2dcp/util.R
#####

## CVXPY SOURCE: reductions/dgp2dcp/util.py
## Utility functions for DGP-to-DCP canonicalization

## explicit_sum: builds x[1] + x[2] + ... + x[n] as an AddExpression tree.
## This is NOT the same as SumEntries (which is a single atom).
## The distinction matters because add_canon expects AddExpression nodes.
## CVXPY SOURCE: util.py lines 19-24
.dgp_explicit_sum <- function(expr) {
  x <- vec(expr)  # (n, 1) column vector
  n <- expr_size(x)
  if (n == 0L) cli_abort("Cannot compute explicit sum of zero-size expression.")
  summation <- x[1]
  if (n > 1L) {
    for (i in 2L:n) {
      summation <- summation + x[i]
    }
  }
  summation
}

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.