R/075_atoms_elementwise_square.R

Defines functions square

Documented in square

#####
## DO NOT EDIT THIS FILE!! EDIT THE SOURCE INSTEAD: rsrc_tree/atoms/elementwise/square.R
#####

## CVXPY SOURCE: atoms/elementwise/square.py
## Square -- convenience wrapper for power(x, 2)

#' Square of an expression: x^2
#'
#' @param x An Expression
#' @returns A `PowerApprox` atom with p=2, the same atom `power(x, 2)` builds
#' @export
square <- function(x) {
  ## CVXPY SOURCE: square.py:20-22 -- `return power(x, 2)`, i.e. the FACTORY,
  ## which yields PowerApprox (measured against CVXPY 1.9.2).  This used to
  ## call `Power(x, 2)` -- the exact class -- and that divergence is visible
  ## in solver selection: exact `Power` is in CVXPY's POWCONE_ATOMS
  ## (atoms/__init__.py:130), so a squared term inside a constraint reported a
  ## required PowCone3D cone and locked out every MISOCP-capable solver that
  ## has no power cone (SCIP, CPLEX, Gurobi).  CVXPY reports {Zero, NonNeg,
  ## SOC} for the same problem.  For p = 2 both classes canonicalize to the
  ## same SOC, so this changes classification, not the cone program.
  power(x, 2)
}

Try the CVXR package in your browser

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

CVXR documentation built on Aug. 24, 2026, 9:10 a.m.