septic_hermite.hpp 3.6 KB

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