Automatic Differentiation
 
Loading...
Searching...
No Matches
integrate_1d_double_exponential.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_FWD_FUNCTOR_INTEGRATE_1D_DOUBLE_EXPONENTIAL_HPP
2#define STAN_MATH_FWD_FUNCTOR_INTEGRATE_1D_DOUBLE_EXPONENTIAL_HPP
3
10
11namespace stan {
12namespace math {
13
35template <typename F, typename T_a, typename T_b, typename... Args,
36 require_any_st_fvar<T_a, T_b, Args...> * = nullptr>
38 const F &f, const T_a &a, const T_b &b, double relative_tolerance,
39 double absolute_tolerance, int max_refinements, std::ostream *msgs,
40 const Args &... args) {
41 using FvarT = scalar_type_t<return_type_t<T_a, T_b, Args...>>;
42
43 auto a_val = value_of(a);
44 auto b_val = value_of(b);
45 auto func = [f, msgs, relative_tolerance, absolute_tolerance, max_refinements,
46 a_val, b_val](const auto &... args_var) {
48 f, a_val, b_val, relative_tolerance, absolute_tolerance,
49 max_refinements, msgs, args_var...);
50 };
51 FvarT ret = finite_diff(func, args...);
53 if constexpr (is_fvar<T_a>::value) {
54 ret.d_ += a.d_ * -f(a_val, 0.0, msgs, value_of(args)...);
55 }
56 if constexpr (is_fvar<T_b>::value) {
57 ret.d_ += b.d_ * f(b_val, 0.0, msgs, value_of(args)...);
58 }
59 }
60 return ret;
61}
62
84template <typename F, typename T_a, typename T_b, typename... Args,
85 require_any_st_fvar<T_a, T_b, Args...> * = nullptr>
87 const F &f, const T_a &a, const T_b &b, double relative_tolerance,
88 double absolute_tolerance, int max_refinements, std::ostream *msgs,
89 const Args &... args) {
91 f, a, b, std::sqrt(EPSILON), 0.0,
93}
94
95} // namespace math
96} // namespace stan
97#endif
require_any_t< is_fvar< scalar_type_t< std::decay_t< Types > > >... > require_any_st_fvar
Require any of the scalar types satisfy is_fvar.
Definition is_fvar.hpp:101
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
return_type_t< T_a, T_b, Args... > integrate_1d_double_exponential_impl(const F &f, const T_a &a, const T_b &b, double relative_tolerance, double absolute_tolerance, int max_refinements, std::ostream *msgs, const Args &... args)
Compute the integral of the single variable function f from a to b using adaptive double-exponential ...
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_double_exponential_tol(const F &f, const T_a &a, const T_b &b, double relative_tolerance, double absolute_tolerance, int max_refinements, std::ostream *msgs, const Args &... args)
Return the integral of f from a to b using adaptive double-exponential quadrature,...
constexpr int INTEGRATE_1D_DOUBLE_EXPONENTIAL_MAX_REFINEMENTS
Default maximum refinement count used by integrate_1d_double_exponential when the user does not pass ...
auto finite_diff(const F &func, const TArgs &... args)
Construct an fvar<T> where the tangent is calculated by finite-differencing.
typename scalar_type< T >::type scalar_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Defines a static member function type which is defined to be false as the primitive scalar types cann...
Definition is_fvar.hpp:15