Automatic Differentiation
 
Loading...
Searching...
No Matches
integrate_1d.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUNCTOR_integrate_1d_HPP
2#define STAN_MATH_REV_FUNCTOR_integrate_1d_HPP
3
11#include <cmath>
12#include <ostream>
13#include <vector>
14
15namespace stan {
16namespace math {
17
34template <typename F, typename T_a, typename T_b, typename... Args,
35 require_any_st_var<T_a, T_b, Args...> * = nullptr>
36inline return_type_t<T_a, T_b, Args...> integrate_1d_impl(
37 const F &f, const T_a &a, const T_b &b, double relative_tolerance,
38 std::ostream *msgs, const Args &... args) {
39 static constexpr const char *function = "integrate_1d";
40 check_less_or_equal(function, "lower limit", a, b);
42 function, f, a, b,
43 [&](auto &&integrand) {
44 return integrate(std::forward<decltype(integrand)>(integrand),
45 value_of(a), value_of(b), relative_tolerance);
46 },
47 msgs, args...);
48}
49
105template <typename F, typename T_a, typename T_b, typename T_theta,
106 typename = require_any_var_t<T_a, T_b, T_theta>>
107inline return_type_t<T_a, T_b, T_theta> integrate_1d(
108 const F &f, const T_a &a, const T_b &b, const std::vector<T_theta> &theta,
109 const std::vector<double> &x_r, const std::vector<int> &x_i,
110 std::ostream *msgs, const double relative_tolerance = std::sqrt(EPSILON)) {
111 return integrate_1d_impl(integrate_1d_adapter<F>(f), a, b, relative_tolerance,
112 msgs, theta, x_r, x_i);
113}
114
115} // namespace math
116} // namespace stan
117
118#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.
static constexpr double EPSILON
Smallest positive value.
Definition constants.hpp:41
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_impl(const F &f, const T_a &a, const T_b &b, double relative_tolerance, std::ostream *msgs, const Args &... args)
Return the integral of f from a to b to the given relative tolerance.
return_type_t< T_a, T_b, T_theta > integrate_1d(const F &f, const T_a &a, const T_b &b, const std::vector< T_theta > &theta, const std::vector< double > &x_r, const std::vector< int > &x_i, std::ostream *msgs, const double relative_tolerance)
Compute the integral of the single variable function f from a to b to within a specified relative tol...
double integrate(const F &f, double a, double b, double relative_tolerance)
Integrate a single variable function f from a to b to within a specified relative tolerance.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Adapt the non-variadic integrate_1d arguments to the variadic integrate_1d_impl interface.