septic_hermite.hpp 3.7 KB

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