sinh_sinh.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright Nick Thompson, 2017
  2. // Copyright Matt Borland, 2024
  3. // Use, modification and distribution are subject to the
  4. // Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt
  6. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. /*
  8. * This class performs sinh-sinh quadrature over the entire real line.
  9. *
  10. * References:
  11. *
  12. * 1) Tanaka, Ken'ichiro, et al. "Function classes for double exponential integration formulas." Numerische Mathematik 111.4 (2009): 631-655.
  13. */
  14. #ifndef BOOST_MATH_QUADRATURE_SINH_SINH_HPP
  15. #define BOOST_MATH_QUADRATURE_SINH_SINH_HPP
  16. #include <boost/math/tools/config.hpp>
  17. #include <boost/math/tools/precision.hpp>
  18. #include <boost/math/tools/cstdint.hpp>
  19. #include <boost/math/quadrature/detail/sinh_sinh_detail.hpp>
  20. #include <boost/math/policies/error_handling.hpp>
  21. #ifndef BOOST_MATH_HAS_NVRTC
  22. #include <cmath>
  23. #include <limits>
  24. #include <memory>
  25. namespace boost{ namespace math{ namespace quadrature {
  26. template<class Real, class Policy = boost::math::policies::policy<> >
  27. class sinh_sinh
  28. {
  29. public:
  30. sinh_sinh(size_t max_refinements = 9)
  31. : m_imp(std::make_shared<detail::sinh_sinh_detail<Real, Policy> >(max_refinements)) {}
  32. template<class F>
  33. auto integrate(const F f, Real tol = boost::math::tools::root_epsilon<Real>(), Real* error = nullptr, Real* L1 = nullptr, std::size_t* levels = nullptr) const ->decltype(std::declval<F>()(std::declval<Real>()))
  34. {
  35. return m_imp->integrate(f, tol, error, L1, levels);
  36. }
  37. private:
  38. std::shared_ptr<detail::sinh_sinh_detail<Real, Policy>> m_imp;
  39. };
  40. }}}
  41. #endif // BOOST_MATH_HAS_NVRTC
  42. #ifdef BOOST_MATH_ENABLE_CUDA
  43. namespace boost {
  44. namespace math {
  45. namespace quadrature {
  46. template <class F, class Real, class Policy = boost::math::policies::policy<> >
  47. __device__ auto sinh_sinh_integrate(const F& f, Real tol = boost::math::tools::root_epsilon<Real>(), Real* error = nullptr, Real* L1 = nullptr, boost::math::size_t* levels = nullptr)
  48. {
  49. return detail::sinh_sinh_integrate_impl(f, tol, error, L1, levels);
  50. }
  51. } // namespace quadrature
  52. } // namespace math
  53. } // namespace boost
  54. #endif // BOOST_MATH_ENABLE_CUDA
  55. #endif // BOOST_MATH_QUADRATURE_SINH_SINH_HPP