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...);
133 throw InterpolationException() <<
"values and coordinates dimensionalities must match: " << values.shape().size()
137 throw InterpolationException() <<
"The size of the grid and the size of the values do not match: "
138 << m_knots.size() <<
" != " << m_values.size();
171template <
typename T,
typename... Rest>
187 throw InterpolationException() <<
"values and coordinates dimensionality must match: " << values.shape().size()
193 throw InterpolationException(
"coordinates and value sizes must match");
198 for (
size_t i = 0; i <
m_knots.size(); ++i) {
199 auto subvalues = values.
rslice(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)