Automatic Differentiation
 
Loading...
Searching...
No Matches
tanh.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_TANH_HPP
2#define STAN_MATH_REV_FUN_TANH_HPP
3
9#include <cmath>
10#include <complex>
11
12namespace stan {
13namespace math {
14
42inline var tanh(const var& a) {
43 return make_callback_var(std::tanh(a.val()), [a](const auto& vi) mutable {
44 const auto a_cosh = std::cosh(a.val());
45 a.adj() += vi.adj_ / (a_cosh * a_cosh);
46 });
47}
48
56template <typename VarMat, require_var_matrix_t<VarMat>* = nullptr>
57inline auto tanh(const VarMat& a) {
58 return make_callback_var(
59 a.val().array().tanh().matrix(), [a](const auto& vi) mutable {
60 a.adj().array() += vi.adj_.array() / (a.val().array().cosh().square());
61 });
62}
63
70inline std::complex<var> tanh(const std::complex<var>& z) {
72}
73
74} // namespace math
75} // namespace stan
76#endif
std::complex< V > complex_tanh(const std::complex< V > &z)
Return the hyperbolic tangent of the complex argument.
Definition tanh.hpp:71
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...
fvar< T > tanh(const fvar< T > &x)
Definition tanh.hpp:15
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...