Nothing
#####
## DO NOT EDIT THIS FILE!! EDIT THE SOURCE INSTEAD: rsrc_tree/reductions/dcp2cone/canonicalizers/quad_form_canon.R
#####
## CVXPY SOURCE: reductions/dcp2cone/canonicalizers/quad_form_canon.py
## Decomposes P via eigenvalues, then uses sum_squares -> quad_over_lin_canon
quad_form_canon <- function(expr, args, solver_context = NULL) {
result <- decomp_quad(value(args[[2L]]))
scale <- result$scale
M1 <- result$M1
M2 <- result$M2
## Special case: P == 0
if (ncol(M1) == 0L && ncol(M2) == 0L) {
return(list(Constant(0), list()))
}
## CVXPY v1.8.2 fix: reject indefinite P (both M1 and M2 non-empty).
## Previously, the M2 block silently overwrote qexpr from M1, dropping
## the positive eigenvalue contribution entirely.
if (ncol(M1) > 0L && ncol(M2) > 0L) {
cli_abort(c(
"{.fn quad_form} canonicalization does not support indefinite matrices.",
"i" = "P must be positive or negative semidefinite.",
"i" = "If P is intended to be PSD, check for numerical errors in its construction (e.g., use {.code P <- (P + t(P)) / 2} and clip negative eigenvalues)."
))
}
if (ncol(M1) > 0L) {
qexpr <- sum_squares(Constant(t(M1)) %*% args[[1L]])
} else {
scale <- -scale
qexpr <- sum_squares(Constant(t(M2)) %*% args[[1L]])
}
qol_result <- quad_over_lin_canon(qexpr, .args(qexpr), solver_context)
list(scale * qol_result[[1L]], qol_result[[2L]])
}
method(dcp_canonicalize, QuadForm) <- quad_form_canon
method(has_dcp_canon, QuadForm) <- function(expr) TRUE
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.