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
26template <typename T, require_arithmetic_t<T>* = nullptr>
27inline auto log(T&& x) {
28 return std::log(x);
29}
30
38template <typename T, require_complex_bt<std::is_arithmetic, T>* = nullptr>
39inline auto log(T&& x) {
40 return std::log(x);
41}
42
46struct log_fun {
54 template <typename T>
55 static inline auto fun(T&& x) {
56 return log(std::forward<T>(x));
57 }
58};
59
69template <typename Container, require_ad_container_t<Container>* = nullptr>
70inline auto log(Container&& x) {
72 std::forward<Container>(x));
73}
74
83template <typename Container,
85inline auto log(Container&& x) {
86 return apply_vector_unary<Container>::apply(
87 std::forward<Container>(x), [](auto&& v) { return v.array().log(); });
88}
89
90namespace internal {
98template <typename V>
99inline std::complex<V> complex_log(const std::complex<V>& z) {
100 if ((is_nan(z.real()) && is_inf(z.imag()))
101 || (is_inf(z.real()) && is_nan(z.imag()))) {
102 return {INFTY, NOT_A_NUMBER};
103 }
104 V r = sqrt(norm(z));
105 V theta = arg(z);
106 return {log(r), theta};
107}
108} // namespace internal
109
110} // namespace math
111} // namespace stan
112#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_log(const std::complex< V > &z)
Return the natural logarithm of the complex argument.
Definition log.hpp:99
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:20
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:18
fvar< T > sqrt(const fvar< T > &x)
Definition sqrt.hpp:18
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 ...
Base template class for vectorization of unary scalar functions defined by a template class F to a sc...
static auto fun(T &&x)
Return natural log of specified argument.
Definition log.hpp:55
Structure to wrap log() so that it can be vectorized.
Definition log.hpp:46