Files
Flux/include/numerics/interpolation1d/interpolation1d_linear.h
T
Bausager 3a53b6ebf7 interpolation1d
done single-threded 1d interpolations; linear, rational, cubic spline, polynomial and barycentric. Still not done test functions yet. Still missing multi-core options.
2025-09-18 20:18:27 +02:00

30 lines
650 B
C++

#pragma once
#include "./numerics/interpolation1d_base.h"
namespace numerics{
template <typename T>
struct interp_linear : Base_interp<T> {
using Base = Base_interp<T>;
// bring base data members into scope (or use this->xx / this->yy below)
using Base::xx;
using Base::yy;
interp_linear(const utils::Vector<T> &xv, const utils::Vector<T> &yv): Base_interp<T>(xv, &yv[0], 2){}
T rawinterp(int64_t j, T x) override{
if (xx[j]==xx[j+1]){
return yy[j]; // Table is defective, but we can recover.
}else {
return (yy[j] + ((x-xx[j])/(xx[j+1]-xx[j]))*(yy[j+1]-yy[j]));
}
}
};
} // namespace numerics