R/063_atoms_elementwise_minimum.R

Defines functions min_elemwise

Documented in min_elemwise

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

## CVXPY SOURCE: atoms/elementwise/minimum.py
## Minimum -- elementwise minimum of 2+ expressions


Minimum <- new_class("Minimum", parent = Elementwise, package = "CVXR",
  constructor = function(..., id = NULL) {
    args <- list(...)
    if (length(args) < 2L) {
      cli_abort("{.cls Minimum} 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: minimum.py -- nonneg if ALL args nonneg, nonpos if ANY arg nonpos
method(sign_from_args, Minimum) <- function(x) {
  list(
    is_nonneg = .all_args(x, is_nonneg),
    is_nonpos = .any_args(x, is_nonpos)
  )
}

# -- curvature: concave ------------------------------------------
method(is_atom_convex, Minimum) <- function(x) FALSE
method(is_atom_concave, Minimum) <- function(x) TRUE

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

# -- log-log: concave (CVXPY minimum.py lines 56-63) -------------
method(is_atom_log_log_convex, Minimum) <- function(x) FALSE
method(is_atom_log_log_concave, Minimum) <- function(x) TRUE

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

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

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

#' Elementwise minimum of expressions
#'
#' @param ... Expressions (at least 2)
#' @returns A Minimum atom
#' @export
min_elemwise <- function(...) {
  Minimum(...)
}

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.