1#ifndef STAN_MATH_REV_FUN_LOG_COSH_HPP
2#define STAN_MATH_REV_FUN_LOG_COSH_HPP
21template <
typename T, require_arithmetic_t<T>* =
nullptr>
23 const double tanh_x =
tanh(x.val());
25 x.adj() += vi.adj() * tanh_x;
37template <
typename T, require_var_matrix_t<T>* =
nullptr>
39 auto arena_x =
to_arena(std::forward<T>(x));
42 log_cosh(arena_x.val()), [arena_x, tanh_x](
auto& vi)
mutable {
43 arena_x.adj().array() += vi.adj().array() * tanh_x.array();
var_value< plain_type_t< T > > make_callback_var(T &&value, F &&functor)
Creates a new var initialized with a callback_vari with a given value and reverse-pass callback funct...
arena_t< T > to_arena(const T &a)
Converts given argument into a type that either has any dynamic allocation on AD stack or schedules i...
fvar< T > tanh(const fvar< T > &x)
Return the hyperbolic tangent of the argument.
fvar< T > log_cosh(const fvar< T > &x)
Return the natural logarithm of the hyperbolic cosine of the argument.
typename internal::arena_type_impl< std::decay_t< T > >::type arena_t
Determines a type that can be used in place of T that does any dynamic allocations on the AD stack.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...