R/200_reductions_complex2real_canonicalizers_psd_canon.R

Defines functions c2r_psd_canon complex_psd_matrix

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

## CVXPY SOURCE: reductions/complex2real/canonicalizers/psd_canon.py
## PSD constraint: [[Re, -Im], [Im, Re]] >> 0

## CVXPY v1.9.3 fix: #3342 -- the block construction is factored out so that
## Complex2Real can re-impose PSD/NSD on a complex Variable carrying that
## attribute (psd_canon.py:22-29).
complex_psd_matrix <- function(real_part, imag_part) {
  if (is.null(imag_part)) {
    return(real_part)
  }
  if (is.null(real_part)) {
    real_part <- Constant(matrix(0, .shape(imag_part)[1L], .shape(imag_part)[2L]))
  }
  bmat(list(
    list(real_part, -imag_part),
    list(imag_part, real_part)
  ))
}

c2r_psd_canon <- function(expr, real_args, imag_args, real2imag) {
  mat <- complex_psd_matrix(real_args[[1L]], imag_args[[1L]])
  list(list(expr_copy(expr, list(mat))), NULL)
}

Try the CVXR package in your browser

Any scripts or data that you put into this service are public.

CVXR documentation built on Oct. 19, 2026, 5:07 p.m.