R/067_atoms_elementwise_xexp.R

Defines functions xexp

Documented in xexp

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

## CVXPY SOURCE: atoms/elementwise/xexp.py
## Xexp -- elementwise x * exp(x)


Xexp <- new_class("Xexp", parent = Elementwise, package = "CVXR",
  constructor = function(x, 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
    )
    validate_arguments(obj)
    obj
  }
)

# -- sign: tracks argument sign -----------------------------------
method(sign_from_args, Xexp) <- function(x) {
  list(is_nonneg = is_nonneg(x@args[[1L]]),
       is_nonpos = is_nonpos(x@args[[1L]]))
}

# -- curvature: conditionally convex (only when arg nonneg) -------
method(is_atom_convex, Xexp) <- function(x) {
  is_nonneg(x@args[[1L]])
}
method(is_atom_concave, Xexp) <- function(x) FALSE

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

# -- log-log curvature --------------------------------------------
method(is_atom_log_log_convex, Xexp) <- function(x) TRUE
method(is_atom_log_log_concave, Xexp) <- function(x) FALSE

# -- domain: x >= 0 ----------------------------------------------
method(atom_domain, Xexp) <- function(x) {
  list(x@args[[1L]] >= 0)
}

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

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

#' x * exp(x) -- elementwise
#'
#' @param x An Expression
#' @returns An Xexp atom
#' @export
xexp <- function(x) {
  Xexp(x)
}

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.