Automatic Differentiation
 
Loading...
Searching...
No Matches
exp.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_EXP_HPP
2#define STAN_MATH_PRIM_FUN_EXP_HPP
3
8#include <cmath>
9#include <complex>
10#include <limits>
11
12namespace stan {
13namespace math {
14
23template <typename T, require_arithmetic_t<T>* = nullptr>
24inline auto exp(const T x) {
25 return std::exp(x);
26}
27
38template <typename T, require_complex_bt<std::is_arithmetic, T>* = nullptr>
39inline auto exp(const T x) {
40 return std::exp(x);
41}
42
47struct exp_fun {
55 template <typename T>
56 static inline auto fun(const T& x) {
57 return exp(x);
58 }
59};
60
70template <typename Container, require_ad_container_t<Container>* = nullptr>
71inline auto exp(const Container& x) {
73}
74
83template <typename Container,
85inline auto exp(const Container& x) {
86 return apply_vector_unary<Container>::apply(
87 x, [](const auto& v) { return v.array().exp(); });
88}
89
90namespace internal {
101template <typename V>
102inline std::complex<V> complex_exp(const std::complex<V>& z) {
103 if (is_inf(z.real()) && z.real() > 0) {
104 if (is_nan(z.imag()) || z.imag() == 0) {
105 // (+inf, nan), (+inf, 0)
106 return z;
107 } else if (is_inf(z.imag()) && z.imag() > 0) {
108 // (+inf, +inf)
109 return {z.real(), std::numeric_limits<double>::quiet_NaN()};
110 } else if (is_inf(z.imag()) && z.imag() < 0) {
111 // (+inf, -inf)
112 return {std::numeric_limits<double>::quiet_NaN(),
113 std::numeric_limits<double>::quiet_NaN()};
114 }
115 }
116 if (is_inf(z.real()) && z.real() < 0
117 && (is_nan(z.imag()) || is_inf(z.imag()))) {
118 // (-inf, nan), (-inf, -inf), (-inf, inf)
119 return {0, 0};
120 }
121 if (is_nan(z.real()) && z.imag() == -0.0) {
122 // (nan, -0)
123 return z;
124 }
125 V exp_re = exp(z.real());
126 return {exp_re * cos(z.imag()), exp_re * sin(z.imag())};
127}
128} // namespace internal
129} // namespace math
130} // namespace stan
131
132#endif
require_t< container_type_check_base< is_container, base_type_t, TypeCheck, Check... > > require_container_bt
Require type satisfies is_container.
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
fvar< T > sin(const fvar< T > &x)
Definition sin.hpp:16
bool is_nan(T &&x)
Returns 1 if the input's value is NaN and 0 otherwise.
Definition is_nan.hpp:22
fvar< T > cos(const fvar< T > &x)
Definition cos.hpp:16
int is_inf(const fvar< T > &x)
Returns 1 if the input's value is infinite and 0 otherwise.
Definition is_inf.hpp:21
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 ...
Base template class for vectorization of unary scalar functions defined by a template class F to a sc...
static auto fun(const T &x)
Return the exponential of the specified scalar argument.
Definition exp.hpp:56
Structure to wrap exp() so that it can be vectorized.
Definition exp.hpp:47