1#ifndef STAN_MATH_PRIM_FUNCTOR_INTEGRATE_1D_GAUSS_KRONROD_HPP
2#define STAN_MATH_PRIM_FUNCTOR_INTEGRATE_1D_GAUSS_KRONROD_HPP
8#include <boost/math/quadrature/gauss_kronrod.hpp>
74 double relative_tolerance,
double absolute_tolerance,
76 static constexpr const char* function =
"integrate_1d_gauss_kronrod";
83 auto f_wrap = [&f](
double x) {
return f(x,
NOT_A_NUMBER); };
85 using boost::math::quadrature::gauss_kronrod;
86 const unsigned int depth
87 = max_depth < 0 ? 0u : static_cast<unsigned int>(max_depth);
88 double Q = gauss_kronrod<double, INTEGRATE_1D_GAUSS_KRONROD_ORDER>::integrate(
89 f_wrap, a, b, depth, relative_tolerance, &error, &L1);
95 const double convergence_threshold
96 = std::max(relative_tolerance * L1, absolute_tolerance);
97 if (error > convergence_threshold) {
100 function,
"error estimate of integral", error,
"",
101 " exceeds max(relative_tolerance * L1, absolute_tolerance)");
125template <
typename F,
typename... Args,
128 double relative_tolerance,
129 double absolute_tolerance,
130 int max_depth, std::ostream* msgs,
131 const Args&... args) {
132 static constexpr const char* function =
"integrate_1d_gauss_kronrod";
143 [&](
auto&& x,
auto&& xc) {
return f(x, xc, msgs, args...); }, a, b,
144 relative_tolerance, absolute_tolerance, max_depth);
180template <
typename F,
typename... Args,
184 const Args&... args) {
require_all_t< std::is_arithmetic< scalar_type_t< std::decay_t< Types > > >... > require_all_st_arithmetic
Require all of the scalar types satisfy std::is_arithmetic.
void check_less_or_equal(const char *function, const char *name, const T_y &y, const T_high &high, Idxs... idxs)
Throw an exception if y is not less than high.
static constexpr double NOT_A_NUMBER
(Quiet) not-a-number value.
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
static constexpr double EPSILON
Smallest positive value.
return_type_t< T_a, T_b, Args... > integrate_1d_gauss_kronrod_tol(const F &f, const T_a &a, const T_b &b, double relative_tolerance, double absolute_tolerance, int max_depth, std::ostream *msgs, const Args &... args)
Return the integral of f from a to b using adaptive Gauss-Kronrod (G21,K21) quadrature,...
constexpr unsigned int INTEGRATE_1D_GAUSS_KRONROD_ORDER
Default Kronrod order used by integrate_1d_gauss_kronrod.
constexpr int INTEGRATE_1D_GAUSS_KRONROD_MAX_DEPTH
Default recursive bisection depth used by integrate_1d_gauss_kronrod when the user does not pass one ...
void throw_domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.
return_type_t< T_a, T_b, Args... > integrate_1d_gauss_kronrod(const F &f, const T_a &a, const T_b &b, std::ostream *msgs, const Args &... args)
Return the integral of f from a to b using adaptive Gauss-Kronrod (G21,K21) quadrature,...
double integrate_gk(const F &f, double a, double b, double relative_tolerance, double absolute_tolerance, int max_depth)
Integrate a single variable function f from a to b using Boost's adaptive Gauss-Kronrod (G21,...
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
bool isinf(const stan::math::var &a)
Return 1 if the specified argument is positive infinity or negative infinity and 0 otherwise.