quintic_hermite.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright Nick Thompson, 2020
  3. * Use, modification and distribution are subject to the
  4. * Boost Software License, Version 1.0. (See accompanying file
  5. * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #ifndef BOOST_MATH_INTERPOLATORS_QUINTIC_HERMITE_HPP
  8. #define BOOST_MATH_INTERPOLATORS_QUINTIC_HERMITE_HPP
  9. #include <algorithm>
  10. #include <stdexcept>
  11. #include <memory>
  12. #include <boost/math/interpolators/detail/quintic_hermite_detail.hpp>
  13. namespace boost::math::interpolators {
  14. template<class RandomAccessContainer>
  15. class quintic_hermite {
  16. public:
  17. using Real = typename RandomAccessContainer::value_type;
  18. quintic_hermite(RandomAccessContainer && x, RandomAccessContainer && y, RandomAccessContainer && dydx, RandomAccessContainer && d2ydx2)
  19. : impl_(std::make_shared<detail::quintic_hermite_detail<RandomAccessContainer>>(std::move(x), std::move(y), std::move(dydx), std::move(d2ydx2)))
  20. {}
  21. Real operator()(Real x) const
  22. {
  23. return impl_->operator()(x);
  24. }
  25. Real prime(Real x) const
  26. {
  27. return impl_->prime(x);
  28. }
  29. Real double_prime(Real x) const
  30. {
  31. return impl_->double_prime(x);
  32. }
  33. friend std::ostream& operator<<(std::ostream & os, const quintic_hermite & m)
  34. {
  35. os << *m.impl_;
  36. return os;
  37. }
  38. void push_back(Real x, Real y, Real dydx, Real d2ydx2)
  39. {
  40. impl_->push_back(x, y, dydx, d2ydx2);
  41. }
  42. int64_t bytes() const
  43. {
  44. return impl_->bytes() + sizeof(impl_);
  45. }
  46. std::pair<Real, Real> domain() const
  47. {
  48. return impl_->domain();
  49. }
  50. private:
  51. std::shared_ptr<detail::quintic_hermite_detail<RandomAccessContainer>> impl_;
  52. };
  53. template<class RandomAccessContainer>
  54. class cardinal_quintic_hermite {
  55. public:
  56. using Real = typename RandomAccessContainer::value_type;
  57. cardinal_quintic_hermite(RandomAccessContainer && y, RandomAccessContainer && dydx, RandomAccessContainer && d2ydx2, Real x0, Real dx)
  58. : impl_(std::make_shared<detail::cardinal_quintic_hermite_detail<RandomAccessContainer>>(std::move(y), std::move(dydx), std::move(d2ydx2), x0, dx))
  59. {}
  60. inline Real operator()(Real x) const {
  61. return impl_->operator()(x);
  62. }
  63. inline Real prime(Real x) const {
  64. return impl_->prime(x);
  65. }
  66. inline Real double_prime(Real x) const
  67. {
  68. return impl_->double_prime(x);
  69. }
  70. int64_t bytes() const
  71. {
  72. return impl_->bytes() + sizeof(impl_);
  73. }
  74. std::pair<Real, Real> domain() const
  75. {
  76. return impl_->domain();
  77. }
  78. private:
  79. std::shared_ptr<detail::cardinal_quintic_hermite_detail<RandomAccessContainer>> impl_;
  80. };
  81. template<class RandomAccessContainer>
  82. class cardinal_quintic_hermite_aos {
  83. public:
  84. using Point = typename RandomAccessContainer::value_type;
  85. using Real = typename Point::value_type;
  86. cardinal_quintic_hermite_aos(RandomAccessContainer && data, Real x0, Real dx)
  87. : impl_(std::make_shared<detail::cardinal_quintic_hermite_detail_aos<RandomAccessContainer>>(std::move(data), x0, dx))
  88. {}
  89. inline Real operator()(Real x) const
  90. {
  91. return impl_->operator()(x);
  92. }
  93. inline Real prime(Real x) const
  94. {
  95. return impl_->prime(x);
  96. }
  97. inline Real double_prime(Real x) const
  98. {
  99. return impl_->double_prime(x);
  100. }
  101. int64_t bytes() const
  102. {
  103. return impl_->bytes() + sizeof(impl_);
  104. }
  105. std::pair<Real, Real> domain() const
  106. {
  107. return impl_->domain();
  108. }
  109. private:
  110. std::shared_ptr<detail::cardinal_quintic_hermite_detail_aos<RandomAccessContainer>> impl_;
  111. };
  112. }
  113. #endif