R/062_atoms_elementwise_maximum.R

Defines functions max_elemwise

Documented in max_elemwise

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

## CVXPY SOURCE: atoms/elementwise/maximum.py
## Maximum -- elementwise maximum of 2+ expressions


Maximum <- new_class("Maximum", parent = Elementwise, package = "CVXR",
  constructor = function(..., id = NULL) {
    args <- list(...)
    if (length(args) < 2L) {
      cli_abort("{.cls Maximum} requires at least 2 arguments.")
    }
    if (is.null(id)) id <- next_expr_id()
    args <- lapply(args, as_expr)
    shape <- sum_shapes(lapply(args, function(a) a@shape))
    obj <- new_object(S7_object(),
      id    = as.integer(id),
      .cache = new.env(parent = emptyenv()),
      args  = args,
      shape = shape
    )
    validate_arguments(obj)
    obj
  }
)

# -- sign ---------------------------------------------------------
## CVXPY: maximum.py -- nonneg if ANY arg nonneg, nonpos if ALL args nonpos
method(sign_from_args, Maximum) <- function(x) {
  list(
    is_nonneg = .any_args(x, is_nonneg),
    is_nonpos = .all_args(x, is_nonpos)
  )
}

# -- curvature: convex --------------------------------------------
method(is_atom_convex, Maximum) <- function(x) TRUE
method(is_atom_concave, Maximum) <- function(x) FALSE

# -- monotonicity: always increasing ------------------------------
method(is_incr, Maximum) <- function(x, idx, ...) TRUE
method(is_decr, Maximum) <- function(x, idx, ...) FALSE

# -- log-log: convex (CVXPY maximum.py lines 64-72) --------------
method(is_atom_log_log_convex, Maximum) <- function(x) TRUE
method(is_atom_log_log_concave, Maximum) <- function(x) FALSE

# -- PWL ----------------------------------------------------------
method(is_pwl, Maximum) <- function(x) {
  .all_args(x, is_pwl)
}

# -- numeric ------------------------------------------------------
method(numeric_value, Maximum) <- function(x, values, ...) {
  Reduce(pmax, values)
}

# -- graph_implementation: stub -----------------------------------
method(graph_implementation, Maximum) <- function(x, arg_objs, shape, data = NULL, ...) {
  cli_abort("graph_implementation for {.cls Maximum} not yet implemented.")
}

#' Elementwise maximum of expressions
#'
#' @param ... Expressions (at least 2)
#' @returns A Maximum atom
#' @export
max_elemwise <- function(...) {
  Maximum(...)
}

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.