R/063_atoms_elementwise_exp.R

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

## CVXPY SOURCE: atoms/elementwise/exp.py
## Exp -- elementwise exponential exp(x)


Exp <- new_class("Exp", parent = Elementwise, package = "CVXR",
  constructor = function(x, id = NULL) {
    if (FALSE) new_object(S7_object())  ## S7 static-check guard
    if (is.null(id)) id <- next_expr_id()
    x <- as_expr(x)
    shape <- .shape(x)
    obj <- .fast_new(Exp, S7_object(),
      id    = as.integer(id),
      .cache = new.env(parent = emptyenv()),
      args  = list(x),
      shape = shape
    )
    validate_arguments(obj)
    obj
  }
)

# -- bounds: exp is monotone increasing (#3080) -------------------
## CVXPY SOURCE: elementwise/exp.py:54-57.
method(bounds_from_args, Exp) <- function(x) {
  b <- get_bounds(.args(x)[[1L]])
  exp_bounds(b[[1L]], b[[2L]])
}

# -- sign: always positive ----------------------------------------
method(sign_from_args, Exp) <- function(x) {
  list(is_nonneg = TRUE, is_nonpos = FALSE)
}

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

## CVXPY elementwise/exp.py: exp is smooth.
method(is_atom_smooth, Exp) <- function(x) TRUE

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

# -- log-log: convex (CVXPY exp.py lines 52-60) ------------------
method(is_atom_log_log_convex, Exp) <- function(x) TRUE
method(is_atom_log_log_concave, Exp) <- function(x) FALSE

# -- numeric ------------------------------------------------------
method(numeric_value, Exp) <- function(x, values, ...) {
  exp(values[[1L]])
}

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

# -- .grad: per-atom subgradient ----------------------------------
## CVXPY SOURCE: atoms/elementwise/exp.py (exp._grad).
## d/dx exp(x) = exp(x), elementwise diagonal.
method(.grad, Exp) <- function(x, values, ...) {
  rows <- as.integer(prod(.arg_shape(x)))
  cols <- as.integer(prod(.shape(x)))
  list(.elemwise_grad_to_diag(exp(values[[1L]]), rows, cols))
}

Try the CVXR package in your browser

Any scripts or data that you put into this service are public.

CVXR documentation built on Aug. 24, 2026, 9:10 a.m.