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 {
18struct exp_fun {
26 template <typename T>
27 static inline auto fun(const T& x) {
28 using std::exp;
29 return exp(x);
30 }
31};
32
42template <
43 typename Container,
47inline auto exp(const Container& x) {
49}
50
59template <typename Container,
61inline auto exp(const Container& x) {
63 x, [](const auto& v) { return v.array().exp(); });
64}
65
66namespace internal {
77template <typename V>
78inline std::complex<V> complex_exp(const std::complex<V>& z) {
79 if (is_inf(z.real()) && z.real() > 0) {
80 if (is_nan(z.imag()) || z.imag() == 0) {
81 // (+inf, nan), (+inf, 0)
82 return z;
83 } else if (is_inf(z.imag()) && z.imag() > 0) {
84 // (+inf, +inf)
85 return {z.real(), std::numeric_limits<double>::quiet_NaN()};
86 } else if (is_inf(z.imag()) && z.imag() < 0) {
87 // (+inf, -inf)
88 return {std::numeric_limits<double>::quiet_NaN(),
89 std::numeric_limits<double>::quiet_NaN()};
90 }
91 }
92 if (is_inf(z.real()) && z.real() < 0
93 && (is_nan(z.imag()) || is_inf(z.imag()))) {
94 // (-inf, nan), (-inf, -inf), (-inf, inf)
95 return {0, 0};
96 }
97 if (is_nan(z.real()) && z.imag() == -0.0) {
98 // (nan, -0)
99 return z;
100 }
101 V exp_re = exp(z.real());
102 return {exp_re * cos(z.imag()), exp_re * sin(z.imag())};
103}
104} // namespace internal
105} // namespace math
106} // namespace stan
107
108#endif
require_not_t< container_type_check_base< is_container, scalar_type_t, TypeCheck, Check... > > require_not_container_st
Require type does not satisfy is_container.
require_t< container_type_check_base< is_container, scalar_type_t, TypeCheck, Check... > > require_container_st
Require type satisfies is_container.
require_not_t< is_nonscalar_prim_or_rev_kernel_expression< std::decay_t< T > > > require_not_nonscalar_prim_or_rev_kernel_expression_t
Require type does not satisfy is_nonscalar_prim_or_rev_kernel_expression.
require_not_t< is_var_matrix< std::decay_t< T > > > require_not_var_matrix_t
Require type does not satisfy is_var_matrix.
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
fvar< T > sin(const fvar< T > &x)
Definition sin.hpp:14
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:14
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:13
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:27
Structure to wrap exp() so that it can be vectorized.
Definition exp.hpp:18