Automatic Differentiation
 
Loading...
Searching...
No Matches
integrate_1d_gauss_kronrod.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUNCTOR_INTEGRATE_1D_GAUSS_KRONROD_HPP
2#define STAN_MATH_REV_FUNCTOR_INTEGRATE_1D_GAUSS_KRONROD_HPP
3
11#include <cmath>
12#include <ostream>
13#include <vector>
14
15namespace stan {
16namespace math {
17
38template <typename F, typename T_a, typename T_b, typename... Args,
39 require_any_st_var<T_a, T_b, Args...> * = nullptr>
40inline return_type_t<T_a, T_b, Args...> integrate_1d_gauss_kronrod_tol(
41 const F &f, const T_a &a, const T_b &b, double relative_tolerance,
42 double absolute_tolerance, int max_depth, std::ostream *msgs,
43 const Args &... args) {
44 static constexpr const char *function = "integrate_1d_gauss_kronrod";
45 check_less_or_equal(function, "lower limit", a, b);
46 check_nonnegative(function, "max_depth", max_depth);
47 check_nonnegative(function, "absolute_tolerance", absolute_tolerance);
49 function, f, a, b,
50 [&](auto &&integrand) {
51 return integrate_gk(std::forward<decltype(integrand)>(integrand),
52 value_of(a), value_of(b), relative_tolerance,
53 absolute_tolerance, max_depth);
54 },
55 msgs, args...);
56}
57
92template <typename F, typename T_a, typename T_b, typename... Args,
93 require_any_st_var<T_a, T_b, Args...> * = nullptr>
94inline return_type_t<T_a, T_b, Args...> integrate_1d_gauss_kronrod(
95 const F &f, const T_a &a, const T_b &b, std::ostream *msgs,
96 const Args &... args) {
97 return integrate_1d_gauss_kronrod_tol(f, a, b, std::sqrt(EPSILON), 0.0,
99 msgs, args...);
100}
101
102} // namespace math
103} // namespace stan
104
105#endif
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
require_any_t< is_var< scalar_type_t< std::decay_t< Types > > >... > require_any_st_var
Require any of the scalar types satisfy is_var.
Definition is_var.hpp:196
return_type_t< T_a, T_b, Args... > integrate_1d_adjoint(const char *function, const F &f, const T_a &a, const T_b &b, Integrator &&integrator, std::ostream *msgs, const Args &... args)
Build the reverse-mode result of a one-dimensional adaptive quadrature.
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.
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.
Definition constants.hpp:41
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 int INTEGRATE_1D_GAUSS_KRONROD_MAX_DEPTH
Default recursive bisection depth used by integrate_1d_gauss_kronrod when the user does not pass one ...
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition value_of.hpp:18
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 ...