R/170_reductions_dcp2cone_canonicalizers_tr_inv_canon.R

Defines functions tr_inv_canon

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

## CVXPY SOURCE: reductions/dcp2cone/canonicalizers/tr_inv_canon.py
## tr_inv(X) -> sum(u_i) subject to PSD([[X, e_i], [e_i^T, u_i]]) for each i


tr_inv_canon <- function(expr, args, solver_context = NULL) {
  X <- args[[1L]]
  n <- X@shape[1L]
  su <- NULL
  constraints <- list()
  for (i in seq_len(n)) {
    ei <- matrix(0, n, 1L)
    ei[i] <- 1.0
    ui <- Variable(c(1L, 1L))
    R <- bmat(list(list(X, Constant(ei)), list(t(Constant(ei)), ui)))
    constraints <- c(constraints, list(PSD(R)))
    if (is.null(su)) {
      su <- ui
    } else {
      su <- su + ui
    }
  }
  list(su, constraints)
}

method(dcp_canonicalize, TrInv) <- tr_inv_canon
method(has_dcp_canon, TrInv) <- 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.