quintic_hermite.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 {
  14. namespace math {
  15. namespace interpolators {
  16. template<class RandomAccessContainer>
  17. class quintic_hermite {
  18. public:
  19. using Real = typename RandomAccessContainer::value_type;
  20. quintic_hermite(RandomAccessContainer && x, RandomAccessContainer && y, RandomAccessContainer && dydx, RandomAccessContainer && d2ydx2)
  21. : impl_(std::make_shared<detail::quintic_hermite_detail<RandomAccessContainer>>(std::move(x), std::move(y), std::move(dydx), std::move(d2ydx2)))
  22. {}
  23. Real operator()(Real x) const
  24. {
  25. return impl_->operator()(x);
  26. }
  27. Real prime(Real x) const
  28. {
  29. return impl_->prime(x);
  30. }
  31. Real double_prime(Real x) const
  32. {
  33. return impl_->double_prime(x);
  34. }
  35. friend std::ostream& operator<<(std::ostream & os, const quintic_hermite & m)
  36. {
  37. os << *m.impl_;
  38. return os;
  39. }
  40. void push_back(Real x, Real y, Real dydx, Real d2ydx2)
  41. {
  42. impl_->push_back(x, y, dydx, d2ydx2);
  43. }
  44. int64_t bytes() const
  45. {
  46. return impl_->bytes() + sizeof(impl_);
  47. }
  48. std::pair<Real, Real> domain() const
  49. {
  50. return impl_->domain();
  51. }
  52. private:
  53. std::shared_ptr<detail::quintic_hermite_detail<RandomAccessContainer>> impl_;
  54. };
  55. template<class RandomAccessContainer>
  56. class cardinal_quintic_hermite {
  57. public:
  58. using Real = typename RandomAccessContainer::value_type;
  59. cardinal_quintic_hermite(RandomAccessContainer && y, RandomAccessContainer && dydx, RandomAccessContainer && d2ydx2, Real x0, Real dx)
  60. : impl_(std::make_shared<detail::cardinal_quintic_hermite_detail<RandomAccessContainer>>(std::move(y), std::move(dydx), std::move(d2ydx2), x0, dx))
  61. {}
  62. inline Real operator()(Real x) const {
  63. return impl_->operator()(x);
  64. }
  65. inline Real prime(Real x) const {
  66. return impl_->prime(x);
  67. }
  68. inline Real double_prime(Real x) const
  69. {
  70. return impl_->double_prime(x);
  71. }
  72. int64_t bytes() const
  73. {
  74. return impl_->bytes() + sizeof(impl_);
  75. }
  76. std::pair<Real, Real> domain() const
  77. {
  78. return impl_->domain();
  79. }
  80. private:
  81. std::shared_ptr<detail::cardinal_quintic_hermite_detail<RandomAccessContainer>> impl_;
  82. };
  83. template<class RandomAccessContainer>
  84. class cardinal_quintic_hermite_aos {
  85. public:
  86. using Point = typename RandomAccessContainer::value_type;
  87. using Real = typename Point::value_type;
  88. cardinal_quintic_hermite_aos(RandomAccessContainer && data, Real x0, Real dx)
  89. : impl_(std::make_shared<detail::cardinal_quintic_hermite_detail_aos<RandomAccessContainer>>(std::move(data), x0, dx))
  90. {}
  91. inline Real operator()(Real x) const
  92. {
  93. return impl_->operator()(x);
  94. }
  95. inline Real prime(Real x) const
  96. {
  97. return impl_->prime(x);
  98. }
  99. inline Real double_prime(Real x) const
  100. {
  101. return impl_->double_prime(x);
  102. }
  103. int64_t bytes() const
  104. {
  105. return impl_->bytes() + sizeof(impl_);
  106. }
  107. std::pair<Real, Real> domain() const
  108. {
  109. return impl_->domain();
  110. }
  111. private:
  112. std::shared_ptr<detail::cardinal_quintic_hermite_detail_aos<RandomAccessContainer>> impl_;
  113. };
  114. }
  115. }
  116. }
  117. #endif