cubic_hermite.hpp 3.4 KB

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