R/118_atoms_gen_lambda_max.R

Defines functions gen_lambda_max

Documented in gen_lambda_max

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

## CVXPY SOURCE: atoms/gen_lambda_max.py
## GenLambdaMax -- maximum generalized eigenvalue: lambda_max(A, B)


GenLambdaMax <- new_class("GenLambdaMax", parent = Atom, package = "CVXR",
  constructor = function(A, B, id = NULL) {
    if (is.null(id)) id <- next_expr_id()
    A <- as_expr(A)
    B <- as_expr(B)
    shape <- c(1L, 1L)

    obj <- new_object(S7_object(),
      id    = as.integer(id),
      .cache = new.env(parent = emptyenv()),
      args  = list(A, B),
      shape = shape
    )
    validate_arguments(obj)
    obj
  }
)

# -- validate -----------------------------------------------------
## CVXPY: gen_lambda_max.py lines 61-71
method(validate_arguments, GenLambdaMax) <- function(x) {
  A <- x@args[[1L]]
  B <- x@args[[2L]]
  if (length(A@shape) != 2L || A@shape[1L] != A@shape[2L] ||
      B@shape[1L] != B@shape[2L] ||
      !identical(A@shape, B@shape)) {
    cli_abort("The arguments to {.fn gen_lambda_max} must be square matrices of the same dimension.")
  }
  invisible(NULL)
}

# -- shape --------------------------------------------------------
## CVXPY: gen_lambda_max.py lines 73-76 -- returns tuple()
method(shape_from_args, GenLambdaMax) <- function(x) c(1L, 1L)

# -- sign ---------------------------------------------------------
## CVXPY: gen_lambda_max.py lines 78-81 -- (False, False)
method(sign_from_args, GenLambdaMax) <- function(x) {
  list(is_nonneg = FALSE, is_nonpos = FALSE)
}

# -- curvature ----------------------------------------------------
## CVXPY: gen_lambda_max.py lines 83-101 -- not convex, not concave,
## quasiconvex but NOT quasiconcave
method(is_atom_convex, GenLambdaMax) <- function(x) FALSE
method(is_atom_concave, GenLambdaMax) <- function(x) FALSE
method(is_atom_quasiconvex, GenLambdaMax) <- function(x) TRUE
method(is_atom_quasiconcave, GenLambdaMax) <- function(x) FALSE

# -- monotonicity -------------------------------------------------
## CVXPY: gen_lambda_max.py lines 103-111 -- not monotone
method(is_incr, GenLambdaMax) <- function(x, idx, ...) FALSE
method(is_decr, GenLambdaMax) <- function(x, idx, ...) FALSE

# -- numeric ------------------------------------------------------
## CVXPY: gen_lambda_max.py lines 31-40
## Generalized eigenvalue: max eigenvalue of solve(B, A)
method(numeric_value, GenLambdaMax) <- function(x, values, ...) {
  A <- values[[1L]]
  B <- values[[2L]]
  ## Generalized eigenvalue via B^{-1} A
  evals <- Re(eigen(solve(B, A), only.values = TRUE)$values)
  matrix(max(evals), 1L, 1L)
}

# -- domain -------------------------------------------------------
## CVXPY: gen_lambda_max.py lines 42-46 -- [A.H == A, B.H == B, B >> 0]
method(atom_domain, GenLambdaMax) <- function(x) {
  A <- x@args[[1L]]
  B <- x@args[[2L]]
  list(expr_H(A) == A, expr_H(B) == B, PSD(B))
}

# -- get_data -----------------------------------------------------
method(get_data, GenLambdaMax) <- function(x) list()

# -- graph_implementation -----------------------------------------
method(graph_implementation, GenLambdaMax) <- function(x, arg_objs, shape, data = NULL, ...) {
  cli_abort("graph_implementation for {.cls GenLambdaMax} not available; use DQCP bisection.")
}

# ==================================================================
# Convenience function
# ==================================================================

#' Maximum generalized eigenvalue
#'
#' Computes the maximum generalized eigenvalue lambda_max(A, B).
#' Requires A symmetric and B positive semidefinite. This is a quasiconvex atom.
#'
#' @param A A square symmetric matrix expression
#' @param B A square PSD matrix expression of the same dimension as A
#' @returns An expression representing the maximum generalized eigenvalue
#' @export
gen_lambda_max <- function(A, B) {
  GenLambdaMax(A, B)
}

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.