Alexandria  2.25.0
SDC-CH common library for the Euclid project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
interpolation.icpp
Go to the documentation of this file.
1 #ifndef INTERPOLATION_IMPL
2 #error Please, include "MathUtils/interpolation/interpolation.h"
3 #endif
4 
7 
8 namespace Euclid {
9 namespace MathUtils {
10 
11 template <std::size_t, typename Seq>
13 
21 template <std::size_t N, std::size_t... Is>
23  // GCC 4.8 needs this hack
24  template <std::size_t>
25  struct Doubles {
26  using type = double;
27  };
28 
29  template <std::size_t>
30  struct Vectors {
32  };
33 
35  bool extrapolate)
36  : m_interpn(std::tuple<std::vector<typename Doubles<Is>::type>...>{grid[N - Is - 1]...}, values, extrapolate) {
37  if (type != InterpolationType::LINEAR) {
38  throw InterpolationException() << "Only linear interpolation is supported for N-dimensional grids";
39  }
40  }
41 
42  double operator()(typename Doubles<Is>::type... xn) const override {
43  auto as_tuple = std::make_tuple(xn...);
44  return m_interpn(std::get<N - Is - 1>(as_tuple)...);
45  }
46 
47  void operator()(const typename Vectors<Is>::type&..., std::vector<double>&) const override {
48  throw Elements::Exception() << "Not implemented";
49  }
50 
51  std::unique_ptr<NAryFunction<N>> clone() const override {
52  return Euclid::make_unique<InterpNAdapter>(*this);
53  }
54 
55  InterpNAdapter(const InterpNAdapter&) = default;
56 
57 private:
59 };
60 
61 template <std::size_t N>
63  InterpolationType type, bool extrapolate) {
64  return Euclid::make_unique<InterpNAdapter<N, _make_index_sequence<N>>>(grid, values, type, extrapolate);
65 }
66 
67 } // namespace MathUtils
68 } // namespace Euclid
std::unique_ptr< NAryFunction< N > > interpn(const Coordinates< N > &grid, const NdArray::NdArray< double > &values, InterpolationType type, bool extrapolate)
T make_tuple(T...args)
InterpNAdapter(const Coordinates< N > &grid, const NdArray::NdArray< double > &values, InterpolationType type, bool extrapolate)
Interface class representing a function with an arbitrary number of parameters.
Definition: Function.h:104
constexpr std::size_t N
STL class.
STL class.
InterpolationType
Enumeration of the different supported interpolation types.
Definition: interpolation.h:43