Automatic Differentiation
 
Loading...
Searching...
No Matches
log.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_LOG_HPP
2#define STAN_MATH_PRIM_FUN_LOG_HPP
3
12#include <cmath>
13#include <complex>
14#include <limits>
15
16namespace stan {
17namespace math {
18
22struct log_fun {
30 template <typename T>
31 static inline auto fun(const T& x) {
32 using std::log;
33 return log(x);
34 }
35};
36
46template <
47 typename Container,
51inline auto log(const Container& x) {
53}
54
63template <typename Container,
65inline auto log(const Container& x) {
67 x, [](const auto& v) { return v.array().log(); });
68}
69
70namespace internal {
78template <typename V>
79inline std::complex<V> complex_log(const std::complex<V>& z) {
80 if ((is_nan(z.real()) && is_inf(z.imag()))
81 || (is_inf(z.real()) && is_nan(z.imag()))) {
82 return {INFTY, NOT_A_NUMBER};
83 }
84 V r = sqrt(norm(z));
85 V theta = arg(z);
86 return {log(r), theta};
87}
88} // namespace internal
89
90} // namespace math
91} // namespace stan
92#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_log(const std::complex< V > &z)
Return the natural logarithm of the complex argument.
Definition log.hpp:79
static constexpr double NOT_A_NUMBER
(Quiet) not-a-number value.
Definition constants.hpp:56
bool is_nan(T &&x)
Returns 1 if the input's value is NaN and 0 otherwise.
Definition is_nan.hpp:22
fvar< T > norm(const std::complex< fvar< T > > &z)
Return the squared magnitude of the complex argument.
Definition norm.hpp:19
fvar< T > arg(const std::complex< fvar< T > > &z)
Return the phase angle of the complex argument.
Definition arg.hpp:19
fvar< T > log(const fvar< T > &x)
Definition log.hpp:15
fvar< T > sqrt(const fvar< T > &x)
Definition sqrt.hpp:17
int is_inf(const fvar< T > &x)
Returns 1 if the input's value is infinite and 0 otherwise.
Definition is_inf.hpp:21
static constexpr double INFTY
Positive infinity.
Definition constants.hpp:46
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9
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 natural log of specified argument.
Definition log.hpp:31
Structure to wrap log() so that it can be vectorized.
Definition log.hpp:22