R/066_atoms_elementwise_log1p.R

Defines functions log1p_atom

Documented in log1p_atom

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

## CVXPY SOURCE: atoms/elementwise/log1p.py
## Log1p -- elementwise log(1 + x), extends Log


Log1p <- new_class("Log1p", parent = Log, 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 (unlike Log which is unknown) -----
method(sign_from_args, Log1p) <- function(x) {
  list(is_nonneg = is_nonneg(x@args[[1L]]),
       is_nonpos = is_nonpos(x@args[[1L]]))
}

# -- curvature: concave (inherited from Log) ----------------------
# is_atom_convex, is_atom_concave inherited from Log

# -- monotonicity: increasing (inherited from Log) ----------------
# is_incr, is_decr inherited from Log

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

# -- numeric: log(1 + x) -----------------------------------------
method(numeric_value, Log1p) <- function(x, values, ...) {
  log1p(values[[1L]])
}

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

#' Log(1 + x) -- elementwise
#'
#' @param x An Expression
#' @returns A Log1p atom
#' @export
log1p_atom <- function(x) {
  Log1p(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.