R/107_atoms_cummax.R

Defines functions cummax_expr

Documented in cummax_expr

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

## CVXPY SOURCE: atoms/cummax.py
## Cummax -- cumulative maximum along an axis


Cummax <- new_class("Cummax", parent = AxisAtom, package = "CVXR",
  constructor = function(x, axis = 2L, id = NULL) {
    if (is.null(id)) id <- next_expr_id()
    x <- as_expr(x)
    shape <- x@shape

    obj <- new_object(S7_object(),
      id       = as.integer(id),
      .cache   = new.env(parent = emptyenv()),
      args     = list(x),
      shape    = shape,
      axis     = as.integer(axis),
      keepdims = FALSE
    )
    obj
  }
)

## Shape: same as input (cummax preserves shape)
method(shape_from_args, Cummax) <- function(x) {
  x@args[[1L]]@shape
}

## Sign: passthrough from argument
method(sign_from_args, Cummax) <- function(x) {
  list(is_nonneg = is_nonneg(x@args[[1L]]),
       is_nonpos = is_nonpos(x@args[[1L]]))
}

## Curvature: convex
method(is_atom_convex, Cummax) <- function(x) TRUE
method(is_atom_concave, Cummax) <- function(x) FALSE

## Monotonicity: increasing
method(is_incr, Cummax) <- function(x, idx, ...) TRUE
method(is_decr, Cummax) <- function(x, idx, ...) FALSE

## get_data
method(get_data, Cummax) <- function(x) list(x@axis)

## numeric
method(numeric_value, Cummax) <- function(x, values, ...) {
  v <- values[[1L]]
  ax <- x@axis
  if (ax == 2L) {
    ## Cummax down columns (column-wise)
    apply(v, 2L, cummax)
  } else {
    ## Cummax across rows
    t(apply(v, 1L, cummax))
  }
}

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

#' Cumulative maximum along an axis
#'
#' @param x An Expression
#' @param axis 1 (across rows) or 2 (down columns, default)
#' @returns A Cummax atom
#' @export
cummax_expr <- function(x, axis = 2L) {
  Cummax(x, axis)
}

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.