R/169_reductions_dcp2cone_canonicalizers_sigma_max_canon.R

Defines functions sigma_max_canon

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

## CVXPY SOURCE: reductions/dcp2cone/canonicalizers/sigma_max_canon.py
## sigma_max(A) -> t  subject to  PSD([[t*I_n, A], [A^T, t*I_m]])


sigma_max_canon <- function(expr, args, solver_context = NULL) {
  A <- args[[1L]]
  n <- A@shape[1L]
  m <- A@shape[2L]
  t <- Variable()
  ## Build t*I_n and t*I_m using sparse identity matrices
  ## Must convert to dgCMatrix: Diagonal(n) is ddiMatrix -> as(,"generalMatrix") -> dgCMatrix
  I_n <- as(Matrix::Diagonal(n), "generalMatrix")
  I_m <- as(Matrix::Diagonal(m), "generalMatrix")
  tI_n <- t * Constant(I_n)
  tI_m <- t * Constant(I_m)
  X <- bmat(list(list(tI_n, A), list(t(A), tI_m)))
  constr <- list(PSD(X))
  list(t, constr)
}

method(dcp_canonicalize, SigmaMax) <- sigma_max_canon
method(has_dcp_canon, SigmaMax) <- 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.