cubic_hermite.hpp 3.4 KB

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