Automatic Differentiation
 
Loading...
Searching...
No Matches
exp.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_EXP_HPP
2#define STAN_MATH_REV_FUN_EXP_HPP
3
11#include <cmath>
12#include <complex>
13
14namespace stan {
15namespace math {
16
39inline var exp(const var& a) {
40 return make_callback_var(std::exp(a.val()), [a](auto& vi) mutable {
41 a.adj() += vi.adj() * vi.val();
42 });
43}
44
50inline std::complex<var> exp(const std::complex<var>& z) {
51 return internal::complex_exp(z);
52}
53
61template <typename T, require_var_matrix_t<T>* = nullptr>
62inline auto exp(const T& x) {
63 return make_callback_var(
64 x.val().array().exp().matrix(), [x](const auto& vi) mutable {
65 x.adj() += (vi.val().array() * vi.adj().array()).matrix();
66 });
67}
68
69} // namespace math
70} // namespace stan
71#endif
std::complex< V > complex_exp(const std::complex< V > &z)
Return the natural (base e) complex exponentiation of the specified complex argument.
Definition exp.hpp:102
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 > exp(const fvar< T > &x)
Definition exp.hpp:15
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...