R/084_atoms_elementwise_hyperbolic.R

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

## CVXPY SOURCE: atoms/elementwise/hyperbolic.py
## Sinh / Tanh / Asinh / Atanh -- elementwise hyperbolic atoms (CVXPY 1.9.0,
## DNLP).  Smooth and increasing but neither convex nor concave.  NOTE: CVXPY
## 1.9.0 defines NO cosh atom -- only these four (cosh(expr) is unsupported,
## matching CVXPY).  Their _grad is NotImplementedError upstream, so each .grad
## here cli_abort()s with the same message.

# ==================================================================
# sinh(x)
# ==================================================================
Sinh <- new_class("Sinh", 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)
    obj <- .fast_new(Sinh, S7_object(),
      id    = as.integer(id),
      .cache = new.env(parent = emptyenv()),
      args  = list(x),
      shape = .shape(x)
    )
    validate_arguments(obj)
    obj
  }
)

# -- sign: always unknown (hyperbolic.py:36-40) -------------------
method(sign_from_args, Sinh) <- function(x) {
  list(is_nonneg = FALSE, is_nonpos = FALSE)
}

# -- curvature: neither convex nor concave (hyperbolic.py:42-50) --
method(is_atom_convex, Sinh) <- function(x) FALSE
method(is_atom_concave, Sinh) <- function(x) FALSE

# -- smooth: TRUE (hyperbolic.py:52-54) ---------------------------
method(is_atom_smooth, Sinh) <- function(x) TRUE

# -- monotonicity: increasing (hyperbolic.py:56-64) ---------------
method(is_incr, Sinh) <- function(x, idx, ...) TRUE
method(is_decr, Sinh) <- function(x, idx, ...) FALSE

# -- numeric (hyperbolic.py:30-34) --------------------------------
method(numeric_value, Sinh) <- function(x, values, ...) {
  sinh(values[[1L]])
}

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

# -- .grad: not implemented upstream (hyperbolic.py:71-72) --------
method(.grad, Sinh) <- function(x, values, ...) {
  cli_abort("Gradient not implemented for {.fn sinh}.")
}

# ==================================================================
# tanh(x)
# ==================================================================
Tanh <- new_class("Tanh", 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)
    obj <- .fast_new(Tanh, S7_object(),
      id    = as.integer(id),
      .cache = new.env(parent = emptyenv()),
      args  = list(x),
      shape = .shape(x)
    )
    validate_arguments(obj)
    obj
  }
)

# -- sign: always unknown (hyperbolic.py:88-92) -------------------
method(sign_from_args, Tanh) <- function(x) {
  list(is_nonneg = FALSE, is_nonpos = FALSE)
}

# -- curvature: neither convex nor concave (hyperbolic.py:94-102) -
method(is_atom_convex, Tanh) <- function(x) FALSE
method(is_atom_concave, Tanh) <- function(x) FALSE

# -- smooth: TRUE (hyperbolic.py:104-106) -------------------------
method(is_atom_smooth, Tanh) <- function(x) TRUE

# -- monotonicity: increasing (hyperbolic.py:108-116) -------------
method(is_incr, Tanh) <- function(x, idx, ...) TRUE
method(is_decr, Tanh) <- function(x, idx, ...) FALSE

# -- numeric (hyperbolic.py:82-86) --------------------------------
method(numeric_value, Tanh) <- function(x, values, ...) {
  tanh(values[[1L]])
}

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

# -- .grad: not implemented upstream (hyperbolic.py:123-124) ------
method(.grad, Tanh) <- function(x, values, ...) {
  cli_abort("Gradient not implemented for {.fn tanh}.")
}

# ==================================================================
# asinh(x) -- inverse hyperbolic sine
# ==================================================================
Asinh <- new_class("Asinh", 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)
    obj <- .fast_new(Asinh, S7_object(),
      id    = as.integer(id),
      .cache = new.env(parent = emptyenv()),
      args  = list(x),
      shape = .shape(x)
    )
    validate_arguments(obj)
    obj
  }
)

# -- sign: always unknown (hyperbolic.py:140-142) -----------------
method(sign_from_args, Asinh) <- function(x) {
  list(is_nonneg = FALSE, is_nonpos = FALSE)
}

# -- curvature: neither convex nor concave (hyperbolic.py:144-148)-
method(is_atom_convex, Asinh) <- function(x) FALSE
method(is_atom_concave, Asinh) <- function(x) FALSE

# -- smooth: TRUE (hyperbolic.py:150-151) -------------------------
method(is_atom_smooth, Asinh) <- function(x) TRUE

# -- monotonicity: increasing (hyperbolic.py:153-157) -------------
method(is_incr, Asinh) <- function(x, idx, ...) TRUE
method(is_decr, Asinh) <- function(x, idx, ...) FALSE

# -- numeric (hyperbolic.py:134-138) ------------------------------
method(numeric_value, Asinh) <- function(x, values, ...) {
  asinh(values[[1L]])
}

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

# -- .grad: not implemented upstream (hyperbolic.py:162-163) ------
method(.grad, Asinh) <- function(x, values, ...) {
  cli_abort("Gradient not implemented for {.fn asinh}.")
}

# ==================================================================
# atanh(x) -- inverse hyperbolic tangent
# ==================================================================
Atanh <- new_class("Atanh", 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)
    obj <- .fast_new(Atanh, S7_object(),
      id    = as.integer(id),
      .cache = new.env(parent = emptyenv()),
      args  = list(x),
      shape = .shape(x)
    )
    validate_arguments(obj)
    obj
  }
)

# -- sign: always unknown (hyperbolic.py:179-181) -----------------
method(sign_from_args, Atanh) <- function(x) {
  list(is_nonneg = FALSE, is_nonpos = FALSE)
}

# -- curvature: neither convex nor concave (hyperbolic.py:183-187)-
method(is_atom_convex, Atanh) <- function(x) FALSE
method(is_atom_concave, Atanh) <- function(x) FALSE

# -- smooth: TRUE (hyperbolic.py:189-190) -------------------------
method(is_atom_smooth, Atanh) <- function(x) TRUE

# -- monotonicity: increasing (hyperbolic.py:192-196) -------------
method(is_incr, Atanh) <- function(x, idx, ...) TRUE
method(is_decr, Atanh) <- function(x, idx, ...) FALSE

# -- numeric (hyperbolic.py:173-177) ------------------------------
method(numeric_value, Atanh) <- function(x, values, ...) {
  atanh(values[[1L]])
}

# -- domain: -1 <= x <= 1 (hyperbolic.py:199, CVXPY 1.9.2) --------
## Through 1.9.1 upstream wrote this with STRICT inequalities (`x < 1`,
## `x > -1`), which raise "Strict inequalities are not allowed"
## (expression.py:993/1000) -- so atanh._domain was unevaluable upstream and
## CVXR mirrored that by aborting.  1.9.2 relaxed both to non-strict, making
## the domain a normal two-constraint list; the closed interval is the
## closure of the true open domain.
method(atom_domain, Atanh) <- function(x) {
  arg <- .args(x)[[1L]]
  list(arg <= 1, arg >= -1)
}

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

# -- .grad: not implemented upstream (hyperbolic.py:201-202) ------
method(.grad, Atanh) <- function(x, values, ...) {
  cli_abort("Gradient not implemented for {.fn atanh}.")
}

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.