R/030_atoms_affine_real.R

Defines functions real_expr

Documented in real_expr

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

## CVXPY SOURCE: atoms/affine/real.py
## Real_ -- extract the real part of an expression


Real_ <- new_class("Real_", parent = AffAtom, package = "CVXR",
  constructor = function(expr, id = NULL) {
    if (is.null(id)) id <- next_expr_id()
    expr <- as_expr(expr)
    shape <- expr@shape

    new_object(S7_object(),
      id    = as.integer(id),
      .cache = new.env(parent = emptyenv()),
      args  = list(expr),
      shape = shape
    )
  }
)

# -- numeric_value: R's native Re() ----------------------------------
## CVXPY SOURCE: real.py lines 29-33

method(numeric_value, Real_) <- function(x, values, ...) {
  Re(values[[1L]])
}

# -- shape_from_args --------------------------------------------------
## CVXPY SOURCE: real.py lines 35-38

method(shape_from_args, Real_) <- function(x) {
  x@args[[1L]]@shape
}

# -- Complex queries: real part is always real ------------------------
## CVXPY SOURCE: real.py lines 40-48

method(is_imag, Real_) <- function(x) FALSE
method(is_complex, Real_) <- function(x) FALSE

# -- Symmetry: Re(Hermitian) is symmetric -----------------------------
## CVXPY SOURCE: real.py lines 49-53

method(is_symmetric, Real_) <- function(x) {
  is_hermitian(x@args[[1L]])
}

# -- No graph_implementation: consumed by Complex2Real reduction ------
## CVXPY real.py has no graph_implementation method.
## These atoms are markers for Complex2Real to split into real/imag parts.

#' Extract Real Part of Expression
#'
#' Returns the real part of a complex expression. R's native \code{Re()}
#' dispatches here for CVXR expressions via the Complex S3 group handler.
#'
#' @param expr A CVXR Expression.
#' @returns A \code{Real_} atom.
#' @keywords internal
real_expr <- function(expr) Real_(expr)

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.