10 #ifndef SRC_INCLUDE_SMASH_INTERPOLATION_H_
11 #define SRC_INCLUDE_SMASH_INTERPOLATION_H_
13 #include <gsl/gsl_errno.h>
14 #include <gsl/gsl_spline.h>
88 std::vector<InterpolateLinear<T>>
f_;
94 slope_ = (y1 - y0) / (x1 - x0);
95 yintercept_ = y0 - slope_ * x0;
100 return slope_ * x + yintercept_;
125 template <
typename T>
128 T res = az * (ax * (ay * f8 + (1.0 - ay) * f6) +
129 (1.0 - ax) * (ay * f7 + (1.0 - ay) * f5)) +
130 (1 - az) * (ax * (ay * f4 + (1.0 - ay) * f2) +
131 (1.0 - ax) * (ay * f3 + (1.0 - ay) * f1));
146 template <
typename T,
typename Cmp>
149 std::iota(
p.begin(),
p.end(), 0);
150 std::sort(
p.begin(),
p.end(),
151 [&](
size_t i,
size_t j) { return compare(v[i], v[j]); });
163 template <
typename T>
166 std::vector<T> copied_v = v;
167 std::transform(
p.begin(),
p.end(), copied_v.begin(),
168 [&](
size_t i) { return v[i]; });
182 template <
typename T>
184 const std::string& error_position) {
185 auto it = std::adjacent_find(x.begin(), x.end());
187 std::stringstream error_msg;
188 error_msg << error_position <<
": Each x value must be unique. \"" << *it
189 <<
"\" was found twice.";
190 throw std::runtime_error(error_msg.str());
194 template <
typename T>
196 const std::vector<T>& y) {
197 assert(x.size() == y.size());
198 const size_t n = x.size();
200 x, [&](T
const& a, T
const& b) {
return a < b; });
205 for (
size_t i = 0; i <
n - 1; i++) {
229 template <
typename T>
231 const auto it = std::lower_bound(v.begin(), v.end(), x);
232 if (it == v.begin()) {
235 return it - 1 - v.begin();
239 template <
typename T>
243 if (i >= f_.size()) {
266 const std::vector<double>& y);
296 #endif // SRC_INCLUDE_SMASH_INTERPOLATION_H_