Alexandria 2.31.2
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
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
8namespace Euclid {
9namespace MathUtils {
10
11template <std::size_t, typename Seq>
13
21template <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
54
55 InterpNAdapter(const InterpNAdapter&) = default;
56
57private:
59};
60
61template <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
Interface class representing a function with an arbitrary number of parameters.
Definition Function.h:104
T make_tuple(T... args)
InterpolationType
Enumeration of the different supported interpolation types.
std::unique_ptr< NAryFunction< N > > interpn(const Coordinates< N > &grid, const NdArray::NdArray< double > &values, InterpolationType type, bool extrapolate)
std::unique_ptr< T > make_unique(Args &&... args)
Constructs an object of type T and wraps it in a std::unique_ptr using args as the parameter list for...
STL namespace.
InterpNAdapter(const Coordinates< N > &grid, const NdArray::NdArray< double > &values, InterpolationType type, bool extrapolate)
void operator()(const typename Vectors< Is >::type &..., std::vector< double > &) const override
std::unique_ptr< NAryFunction< N > > clone() const override
double operator()(typename Doubles< Is >::type... xn) const override