cubic_hermite.hpp 3.4 KB

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