21template <
typename X,
typename Y>
class Spline {
22 static_assert(std::is_floating_point<X>(),
"Splines must have floating point X values");
23 static_assert(std::is_floating_point<Y>(),
"Splines must have floating point Y values");
33 Spline(std::span<X const>
x, std::span<Y const>
y, gsl_interp_type
const *type)
34 :
m_spline(spline::make_spline<
X,
Y>(
x,
y, type)),
m_acc(spline::make_interp_accel()) {}
38 int err = gsl_spline_eval_e(
m_spline.get(), newX,
m_acc.get(), &
y);
39 if (err != GSL_SUCCESS) {
40 throw std::runtime_error(
"Failure in GSL spline interpolation at " +
std::to_string(newX));
44 std::vector<Y>
operator()(std::span<X const> newX)
const {
46 newY.reserve(newX.size());
47 std::transform(newX.begin(), newX.end(), std::back_inserter(newY), [
this](
X const x) { return (*this)(x); });
50 Y deriv(
X const newX,
unsigned int order = 1)
const {
52 int err = GSL_SUCCESS;
56 }
else if (order == 2) {
62 if (err != GSL_SUCCESS) {
63 throw std::runtime_error(
"Failure in GSL spline derivative at " +
std::to_string(newX));
67 std::vector<Y>
deriv(std::span<X const> newX,
unsigned int order = 1)
const {
68 std::vector<Y> derivY;
69 derivY.reserve(newX.size());
70 std::transform(newX.begin(), newX.end(), std::back_inserter(derivY),
71 [
this, order](
X const x) { return this->deriv(x, order); });
84 static std::vector<Y>
getSplinedYValues(std::span<X const> newX, std::span<X const>
x, std::span<Y const>
y) {
98 static std::vector<Y>
getSplinedYValues(std::span<X const> newX, std::span<X const>
x, std::span<Y const>
y) {
Cubic spline interpolation using GSL.
CubicSpline(std::span< X const > x, std::span< Y const > y)
static std::vector< Y > getSplinedYValues(std::span< X const > newX, std::span< X const > x, std::span< Y const > y)
Linear interpolation using GSL.
LinearSpline(std::span< X const > x, std::span< Y const > y)
static std::vector< Y > getSplinedYValues(std::span< X const > newX, std::span< X const > x, std::span< Y const > y)
Generic spline interpolation base class.
Spline & operator=(Spline &&)=delete
std::vector< Y > deriv(std::span< X const > newX, unsigned int order=1) const
Y operator()(X const newX) const
Spline(std::span< X const > x, std::span< Y const > y, gsl_interp_type const *type)
spline::spline_uptr m_spline
Y deriv(X const newX, unsigned int order=1) const
Spline(Spline const &)=delete
std::vector< Y > operator()(std::span< X const > newX) const
Spline & operator=(Spline const &)=delete
virtual ~Spline()=default
std::unique_ptr< gsl_interp_accel, GSLFree > accel_uptr
std::unique_ptr< gsl_spline, GSLFree > spline_uptr
std::string to_string(const wide_integer< Bits, Signed > &n)