Automatic Differentiation
 
Loading...
Searching...
No Matches
lgamma.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_LGAMMA_HPP
2#define STAN_MATH_PRIM_FUN_LGAMMA_HPP
3
15#if !__MINGW32__ && !_BOOST_LGAMMA
16// _REENTRANT must be defined during compilation to ensure that cmath
17// exports the reentrant safe lgamma_r version.
18#if !_REENTRANT
19#error \
20 "stan-math requires _REENTRANT being defined during compilation" \
21 "to make lgamma_r available."
22#endif
23#include <cmath>
24#else
25// MinGW compilers on Windows do not provide the reentrant lgamma_r
26// such that we fall back to boost whenever we are on MinGW.
28#include <boost/math/special_functions/gamma.hpp>
29#include <limits>
30#endif
33
34namespace stan {
35namespace math {
36
63inline double lgamma(double x) {
64#if !__MINGW32__ && !_BOOST_LGAMMA
65 int sign = 1;
66 return ::lgamma_r(x, &sign);
67#else
68 if (unlikely(x == 0.0))
69 return std::numeric_limits<double>::infinity();
70 return boost::math::lgamma(x, boost_policy_t<>());
71#endif
72}
73
82inline double lgamma(int x) {
83#if !__MINGW32__ && !_BOOST_LGAMMA
84 int sign = 1;
85 return ::lgamma_r(x, &sign);
86#else
87 if (unlikely(x == 0.0))
88 return std::numeric_limits<double>::infinity();
89 return boost::math::lgamma(x, boost_policy_t<>());
90#endif
91}
92
102 template <typename T>
103 static inline auto fun(const T& x) {
104 return lgamma(x);
105 }
106};
107
117template <typename T, require_not_var_matrix_t<T>* = nullptr,
118 require_not_nonscalar_prim_or_rev_kernel_expression_t<T>* = nullptr>
119inline auto lgamma(const T& x) {
121}
122
123} // namespace math
124} // namespace stan
125
126#endif
#define unlikely(x)
auto sign(const T &x)
Returns signs of the arguments.
Definition sign.hpp:18
fvar< T > lgamma(const fvar< T > &x)
Return the natural logarithm of the gamma function applied to the specified argument.
Definition lgamma.hpp:21
boost::math::policies::policy< boost::math::policies::overflow_error< boost::math::policies::errno_on_error >, boost::math::policies::pole_error< boost::math::policies::errno_on_error >, boost::math::policies::promote_double< false >, boost::math::policies::digits2< B > > boost_policy_t
Boost policy that overrides the defaults to match the built-in C++ standard library functions.
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)
Definition lgamma.hpp:103
Structure to wrap lgamma() so that it can be vectorized.
Definition lgamma.hpp:101