Alexandria
2.25.0
SDC-CH common library for the Euclid project
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
MathUtils
MathUtils
function
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
28
#include "
AlexandriaKernel/index_sequence.h
"
29
#include "
ElementsKernel/Exception.h
"
30
#include <memory>
31
#include <vector>
32
33
namespace
Euclid {
34
namespace
MathUtils {
35
41
template
<
typename
Seq>
42
class
NAryFunctionImpl
{
43
public
:
44
};
45
52
template
<
std::size_t
... Is>
53
class
NAryFunctionImpl
<
_index_sequence
<Is...>> {
54
public
:
55
template
<std::
size_t
>
56
using
Doubles
= double;
57
58
template
<std::
size_t
>
59
using
Vectors
=
std::vector<double>
;
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
116
using
Function
=
NAryFunction<1>
;
117
119
using
BinaryFunction
=
NAryFunction<2>
;
120
122
using
TernaryFunction
=
NAryFunction<3>
;
123
124
}
// namespace MathUtils
125
}
// end of namespace Euclid
126
127
#endif
/* MATHUTILS_FUNCTION_H */
Euclid::_integer_sequence
Definition:
index_sequence.h:42
std::size_t
Euclid::MathUtils::NAryFunction::clone
virtual std::unique_ptr< NAryFunction > clone() const =0
Euclid::MathUtils::NAryFunction
Interface class representing a function with an arbitrary number of parameters.
Definition:
Function.h:104
std::vector::resize
T resize(T...args)
Euclid::MathUtils::NAryFunctionImpl< _index_sequence< Is...> >::Doubles
double Doubles
Definition:
Function.h:56
std::tuple
std::vector::size
T size(T...args)
std::vector< double >
std::unique_ptr
STL class.
Euclid::MathUtils::NAryFunctionImpl< _index_sequence< Is...> >::operator()
virtual void operator()(const Vectors< Is > &...xs, std::vector< double > &output) const
Definition:
Function.h:80
Exception.h
index_sequence.h
Euclid::MathUtils::NAryFunctionImpl
Definition:
Function.h:42
Generated by
1.8.5