1#ifndef GRIDINTERPOLATION_IMPL
2#error Please, include "MathUtils/interpolation/GridInterpolation.h"
11template <
typename T,
typename Enable =
void>
24 template <
typename... Rest>
29 if ((x < knots.
front() || x > knots.
back()) && !extrapolate) {
33 if (knots.
size() == 1) {
34 return (*interpolators[0])(rest...);
40 }
else if (x2i == knots.
size()) {
45 double y1 = (*interpolators[x1i])(rest...);
46 double y2 = (*interpolators[x2i])(rest...);
62 if (x < knots.
front() || x > knots.
back())
67 template <
typename... Rest>
71 if (x < knots.
front() || x > knots.
back())
73 return (*interpolators[x])(rest...);
77 if (knots.
front() != 0) {
80 for (
auto b = knots.
begin() + 1; b != knots.
end(); ++b) {
81 if (*b - *(b - 1) != 1) {
96 if (i >= knots.
size() || knots[i] != x)
101 template <
typename... Rest>
104 const Rest... rest) {
106 if (i >= knots.
size() || knots[i] != x)
108 return (*interpolators[i])(rest...);
131 : m_knots(
std::get<0>(grid)), m_values(values.begin(), values.end()), m_extrapolate(extrapolate) {
136 if (m_knots.size() != values.
size()) {
138 << m_knots.size() <<
" != " << m_values.size();
171template <
typename T,
typename... Rest>
183 : m_extrapolate(extrapolate) {
190 m_knots = std::get<0>(grid);
192 if (m_knots.size() != values.
shape().
back()) {
197 m_interpolators.resize(m_knots.size());
198 for (
size_t i = 0; i < m_knots.size(); ++i) {
199 auto subvalues = values.
rslice(i);
200 m_interpolators[i].reset(
new InterpN<Rest...>(subgrid, subvalues, extrapolate));
220 InterpN(
const InterpN& other) : m_knots(other.m_knots), m_extrapolate(other.m_extrapolate) {
221 m_interpolators.resize(m_knots.size());
222 for (
size_t i = 0; i < m_interpolators.size(); ++i) {
InterpN(const InterpN &other)
Copy constructor.
std::vector< std::unique_ptr< InterpN< Rest... > > > m_interpolators
double operator()(T x, Rest... rest) const
InterpN(const std::tuple< std::vector< T >, std::vector< Rest >... > &grid, const NdArray::NdArray< double > &values, bool extrapolate)
std::vector< double > m_values
InterpN(const std::tuple< std::vector< T > > &grid, const NdArray::NdArray< double > &values, bool extrapolate)
double operator()(const T x) const
InterpN(InterpN &&)=default
Move constructor.
InterpN(const InterpN &)=default
Copy constructor.
const std::vector< size_t > & shape() const
self_type rslice(size_t i)
ELEMENTS_API double simple_interpolation(double x, const std::vector< double > &xp, const std::vector< double > &yp, bool extrapolate=false)
static std::tuple< Tn... > Tail(std::tuple< T0, Tn... > &&tuple)
static double interpolate(const T x, const std::vector< T > &knots, const std::vector< std::unique_ptr< InterpN< Rest... > > > &interpolators, bool, const Rest... rest)
static double interpolate(const T x, const std::vector< T > &knots, const std::vector< double > &values, bool)
static void checkOrder(const std::vector< T > &knots)
static void checkOrder(const std::vector< T > &knots)
static double interpolate(const T x, const std::vector< T > &knots, const std::vector< double > &values, bool extrapolate)
static double interpolate(const T x, const std::vector< T > &knots, const std::vector< std::unique_ptr< InterpN< Rest... > > > &interpolators, bool extrapolate, const Rest... rest)
static double interpolate(const T x, const std::vector< T > &knots, const std::vector< std::unique_ptr< InterpN< Rest... > > > &interpolators, bool, const Rest... rest)
static void checkOrder(const std::vector< T > &)
static double interpolate(const T x, const std::vector< T > &knots, const std::vector< double > &values, bool)