Nothing
#####
## DO NOT EDIT THIS FILE!! EDIT THE SOURCE INSTEAD: rsrc_tree/reductions/dcp2cone/canonicalizers/quad/quad_over_lin_canon.R
#####
## CVXPY SOURCE: reductions/dcp2cone/canonicalizers/quad/quad_over_lin_canon.py
## Scalar case only (axis=NULL). Builds I/y as the P matrix.
## Non-scalar with axis falls back to cone canon.
qol_quad_canon <- function(expr, args, solver_context = NULL) {
affine_expr <- args[[1L]]
y <- args[[2L]]
## y must be constant scalar (guarded by quad_canonicalize below).
y_val <- as.numeric(value(y))
n <- prod(.shape(affine_expr))
## Keep P sparse: ddiMatrix has implicit unit diagonal that
## Matrix::summary() doesn't report; convert to dgCMatrix for
## explicit entries. Avoids O(n^2) dense matrix from as.matrix().
quad_mat <- as(as(Matrix::Diagonal(n) / y_val, "generalMatrix"), "CsparseMatrix")
if (.s7_is(affine_expr, Variable)) {
list(SymbolicQuadForm(affine_expr, Constant(quad_mat), expr), list())
} else {
t <- Variable(shape = .shape(affine_expr))
list(SymbolicQuadForm(t, Constant(quad_mat), expr), list(affine_expr == t))
}
}
method(quad_canonicalize, QuadOverLin) <- function(expr, args, ...) {
## CVXPY 1.9 parity: decide from the canonicalized denominator, not
## expr@args[[1L]] being PWL. For quad_over_lin(exp(x), 1), exp(x)
## has already canonicalized to an affine variable plus ExpCone.
if (!is.null(expr@axis) || !is_constant(args[[2L]])) return(NULL)
qol_quad_canon(expr, args)
}
## Membership marker for the CSE cache: `affine_above` is part of a subtree's
## cache key only when the quad branch could fire inside it
## (`.affine_above_relevant`, dcp2cone.R). CVXPY reads this off its
## `quad_canon_methods` dict; CVXR needs an explicit predicate per class.
method(has_quad_canon, QuadOverLin) <- 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.