septic_hermite.hpp 3.6 KB

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