Debian Codegraph @

third-party/boost-math/include/boost/math/interpolators/cubic_hermite.hpp

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