1#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_LBETA_HPP
2#define STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_LBETA_HPP
10namespace opencl_kernels {
13static constexpr const char* lbeta_device_function
15 "#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_LBETA\n"
16 "#define STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_LBETA\n" STRINGIFY(
63 if (isnan(a) || isnan(b)) {
93 if (y < LGAMMA_STIRLING_DIFF_USEFUL) {
97 double x_over_xy = x / (x + y);
98 double log_xpy =
log(x + y);
99 if (x < LGAMMA_STIRLING_DIFF_USEFUL) {
104 = (y - 0.5) *
log1p(-x_over_xy) + x * (1 - log_xpy);
105 return stirling +
lgamma(x) + stirling_diff;
112 double stirling = (x - 0.5) * (
log(x) - log_xpy)
113 + y *
log1p(-x_over_xy)
114 + 0.5 * (M_LN2 +
log(M_PI)) - 0.5 *
log(y);
115 return stirling + stirling_diff;
double lgamma_stirling_diff(double x)
Return the difference between log of the gamma function and its Stirling approximation.
double stan_lbeta(double a, double b)
Return the log of the beta function applied to the specified arguments.
fvar< T > log(const fvar< T > &x)
fvar< T > log1p(const fvar< T > &x)
fvar< T > lgamma(const fvar< T > &x)
Return the natural logarithm of the gamma function applied to the specified argument.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...