Automatic Differentiation
 
Loading...
Searching...
No Matches
lmgamma.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_LMGAMMA_HPP
2#define STAN_MATH_PRIM_FUN_LMGAMMA_HPP
3
9
10namespace stan {
11namespace math {
12
54template <typename T, require_arithmetic_t<T>* = nullptr>
55inline return_type_t<T> lmgamma(int k, T x) {
56 return_type_t<T> result = k * (k - 1) * LOG_PI_OVER_FOUR;
57
58 return result + sum(lgamma(x + (1 - Eigen::ArrayXd::LinSpaced(k, 1, k)) / 2));
59}
60
72template <typename T1, typename T2, require_any_container_t<T1, T2>* = nullptr>
73inline auto lmgamma(T1&& a, T2&& b) {
75 [](auto&& c, auto&& d) {
76 return lmgamma(std::forward<decltype(c)>(c),
77 std::forward<decltype(d)>(d));
78 },
79 std::forward<T1>(a), std::forward<T2>(b));
80}
81
82} // namespace math
83} // namespace stan
84#endif
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
static constexpr double LOG_PI_OVER_FOUR
The value of one quarter the natural logarithm of , .
auto apply_scalar_binary(F &&f, T1 &&x, T2 &&y)
Base template function for vectorization of binary scalar functions defined by applying a functor to ...
fvar< return_type_t< T, int > > lmgamma(int x1, const fvar< T > &x2)
Definition lmgamma.hpp:14
fvar< T > lgamma(const fvar< T > &x)
Return the natural logarithm of the gamma function applied to the specified argument.
Definition lgamma.hpp:21
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
Definition sum.hpp:23
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...