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
14#include <cmath>
15#include <complex>
16
17namespace stan {
18namespace math {
19
42inline var exp(const var& a) {
43 return make_callback_var(std::exp(a.val()), [a](auto& vi) mutable {
44 a.adj() += vi.adj() * vi.val();
45 });
46}
47
53inline std::complex<var> exp(const std::complex<var>& z) {
54 return internal::complex_exp(z);
55}
56
64template <typename T, require_var_matrix_t<T>* = nullptr>
65inline auto exp(const T& x) {
66 return make_callback_var(
67 x.val().array().exp().matrix(), [x](const auto& vi) mutable {
68 x.adj() += (vi.val().array() * vi.adj().array()).matrix();
69 });
70}
71
72} // namespace math
73} // namespace stan
74#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:78
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:13
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...