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
Function.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2021 Euclid Science Ground Segment
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License as published by the Free
6  * Software Foundation; either version 3.0 of the License, or (at your option)
7  * any later version.
8  *
9  * This library is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
25 #ifndef MATHUTILS_FUNCTION_H
26 #define MATHUTILS_FUNCTION_H
27 
30 #include <memory>
31 #include <vector>
32 
33 namespace Euclid {
34 namespace MathUtils {
35 
41 template <typename Seq>
43 public:
44 };
45 
52 template <std::size_t... Is>
54 public:
55  template <std::size_t>
56  using Doubles = double;
57 
58  template <std::size_t>
60 
62  virtual ~NAryFunctionImpl() = default;
63 
69  virtual double operator()(Doubles<Is>... xn) const = 0;
70 
80  virtual void operator()(const Vectors<Is>&... xs, std::vector<double>& output) const {
81  output.resize(std::get<0>(std::tuple<const Vectors<Is>&...>(xs...)).size());
82  for (size_t i = 0; i < output.size(); ++i) {
83  output[i] = (*this)(xs[i]...);
84  }
85  }
86 };
87 
103 template <std::size_t N>
104 class NAryFunction : public NAryFunctionImpl<_make_index_sequence<N>> {
105 public:
112  virtual std::unique_ptr<NAryFunction> clone() const = 0;
113 };
114 
117 
120 
123 
124 } // namespace MathUtils
125 } // end of namespace Euclid
126 
127 #endif /* MATHUTILS_FUNCTION_H */
virtual std::unique_ptr< NAryFunction > clone() const =0
Interface class representing a function with an arbitrary number of parameters.
Definition: Function.h:104
T resize(T...args)
T size(T...args)
STL class.
virtual void operator()(const Vectors< Is > &...xs, std::vector< double > &output) const
Definition: Function.h:80