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 7 #ifndef BOOST_MATH_INTERPOLATORS_CUBIC_HERMITE_HPP 8 #define BOOST_MATH_INTERPOLATORS_CUBIC_HERMITE_HPP 9 #include <memory> 10 #include <boost/math/interpolators/detail/cubic_hermite_detail.hpp> 11 12 namespace boost::math::interpolators { 13 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 cubic_hermite(RandomAccessContainer && x, RandomAccessContainer && y, RandomAccessContainer && dydx) 20 : impl_(std::make_shared<detail::cubic_hermite_detail<RandomAccessContainer>>(std::move(x), std::move(y), std::move(dydx))) 21 {} 22 operator ()(Real x) const23 inline Real operator()(Real x) const { 24 return impl_->operator()(x); 25 } 26 prime(Real x) const27 inline Real prime(Real x) const { 28 return impl_->prime(x); 29 } 30 operator <<(std::ostream & os,const cubic_hermite & m)31 friend std::ostream& operator<<(std::ostream & os, const cubic_hermite & m) 32 { 33 os << *m.impl_; 34 return os; 35 } 36 push_back(Real x,Real y,Real dydx)37 void push_back(Real x, Real y, Real dydx) 38 { 39 impl_->push_back(x, y, dydx); 40 } 41 bytes() const42 int64_t bytes() const 43 { 44 return impl_->bytes() + sizeof(impl_); 45 } 46 domain() const47 std::pair<Real, Real> domain() const 48 { 49 return impl_->domain(); 50 } 51 52 private: 53 std::shared_ptr<detail::cubic_hermite_detail<RandomAccessContainer>> impl_; 54 }; 55 56 template<class RandomAccessContainer> 57 class cardinal_cubic_hermite { 58 public: 59 using Real = typename RandomAccessContainer::value_type; 60 cardinal_cubic_hermite(RandomAccessContainer && y,RandomAccessContainer && dydx,Real x0,Real dx)61 cardinal_cubic_hermite(RandomAccessContainer && y, RandomAccessContainer && dydx, Real x0, Real dx) 62 : impl_(std::make_shared<detail::cardinal_cubic_hermite_detail<RandomAccessContainer>>(std::move(y), std::move(dydx), x0, dx)) 63 {} 64 operator ()(Real x) const65 inline Real operator()(Real x) const 66 { 67 return impl_->operator()(x); 68 } 69 prime(Real x) const70 inline Real prime(Real x) const 71 { 72 return impl_->prime(x); 73 } 74 operator <<(std::ostream & os,const cardinal_cubic_hermite & m)75 friend std::ostream& operator<<(std::ostream & os, const cardinal_cubic_hermite & m) 76 { 77 os << *m.impl_; 78 return os; 79 } 80 bytes() const81 int64_t bytes() const 82 { 83 return impl_->bytes() + sizeof(impl_); 84 } 85 domain() const86 std::pair<Real, Real> domain() const 87 { 88 return impl_->domain(); 89 } 90 91 private: 92 std::shared_ptr<detail::cardinal_cubic_hermite_detail<RandomAccessContainer>> impl_; 93 }; 94 95 96 template<class RandomAccessContainer> 97 class cardinal_cubic_hermite_aos { 98 public: 99 using Point = typename RandomAccessContainer::value_type; 100 using Real = typename Point::value_type; 101 cardinal_cubic_hermite_aos(RandomAccessContainer && data,Real x0,Real dx)102 cardinal_cubic_hermite_aos(RandomAccessContainer && data, Real x0, Real dx) 103 : impl_(std::make_shared<detail::cardinal_cubic_hermite_detail_aos<RandomAccessContainer>>(std::move(data), x0, dx)) 104 {} 105 operator ()(Real x) const106 inline Real operator()(Real x) const 107 { 108 return impl_->operator()(x); 109 } 110 prime(Real x) const111 inline Real prime(Real x) const 112 { 113 return impl_->prime(x); 114 } 115 operator <<(std::ostream & os,const cardinal_cubic_hermite_aos & m)116 friend std::ostream& operator<<(std::ostream & os, const cardinal_cubic_hermite_aos & m) 117 { 118 os << *m.impl_; 119 return os; 120 } 121 bytes() const122 int64_t bytes() const 123 { 124 return impl_->bytes() + sizeof(impl_); 125 } 126 domain() const127 std::pair<Real, Real> domain() const 128 { 129 return impl_->domain(); 130 } 131 132 private: 133 std::shared_ptr<detail::cardinal_cubic_hermite_detail_aos<RandomAccessContainer>> impl_; 134 }; 135 136 137 } 138 #endif