R/110_atoms_cumprod.R

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

## CVXPY SOURCE: atoms/cumprod.py
## Cumprod -- cumulative product along an axis
## Log-log affine (T/T), neither convex nor concave.


Cumprod <- new_class("Cumprod", parent = AxisAtom, package = "CVXR",
  constructor = function(x, axis = 2L, id = NULL) {
    if (is.null(id)) id <- next_expr_id()
    x <- as_expr(x)
    axis <- as.integer(axis)
    ## Cumprod preserves shape (like cumsum)
    shape <- x@shape

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

# -- shape: same as input ------------------------------------------
method(shape_from_args, Cumprod) <- function(x) x@args[[1L]]@shape

# -- curvature: neither convex nor concave --------------------------
method(is_atom_convex, Cumprod) <- function(x) FALSE
method(is_atom_concave, Cumprod) <- function(x) FALSE

# -- log-log curvature: affine (T/T) -------------------------------
method(is_atom_log_log_convex, Cumprod) <- function(x) TRUE
method(is_atom_log_log_concave, Cumprod) <- function(x) TRUE

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

# -- numeric --------------------------------------------------------
method(numeric_value, Cumprod) <- function(x, values, ...) {
  v <- values[[1L]]
  ax <- x@axis
  if (ax == 2L) {
    apply(v, 2L, cumprod)
  } else {
    t(apply(v, 1L, cumprod))
  }
}

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

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.