Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
FunAdapters.h
Go to the documentation of this file.
1 #ifndef GAUDIMATH_FUNADAPTERS_H
2 #define GAUDIMATH_FUNADAPTERS_H 1
3 // ============================================================================
4 // Include files
5 // ============================================================================
6 #include <boost/variant.hpp>
7 #include <memory>
8 // ============================================================================
9 // from CLHEP
10 // ============================================================================
11 #include "CLHEP/GenericFunctions/AbsFunction.hh"
12 #include "CLHEP/GenericFunctions/Argument.hh"
13 #include "CLHEP/GenericFunctions/GenericFunctions.hh"
14 // ============================================================================
15 #include "GaudiKernel/Kernel.h"
16 #include "GaudiKernel/compose.h"
17 
18 #if defined( __clang__ ) || defined( __CLING__ )
19 # pragma clang diagnostic push
20 # pragma clang diagnostic ignored "-Winconsistent-missing-override"
21 #elif defined( __GNUC__ ) && __GNUC__ >= 5
22 # pragma GCC diagnostic push
23 # pragma GCC diagnostic ignored "-Wsuggest-override"
24 #endif
25 
26 namespace detail {
27 
28  auto dispatch_variant = []( auto&& variant, auto&&... lambdas ) -> decltype( auto ) {
29  return boost::apply_visitor( compose( std::forward<decltype( lambdas )>( lambdas )... ),
30  std::forward<decltype( variant )>( variant ) );
31  };
32 }
33 
34 namespace AIDA {
35  class IFunction;
36 }
37 
38 namespace Genfun {
39  namespace GaudiMathImplementation {
40  // ========================================================================
47  // =========================================================================
48 
49  class GAUDI_API AdapterIFunction : public AbsFunction {
50  public:
52  FUNCTION_OBJECT_DEF( AdapterIFunction )
53  public:
57  AdapterIFunction( const AIDA::IFunction& fun );
59  AdapterIFunction( const AdapterIFunction& ) = default;
60 
61  double operator()( double a ) const override;
62 
63  double operator()( const Argument& x ) const override;
64 
65  unsigned int dimensionality() const override { return m_arg.size(); }
66 
68  bool hasAnalyticDerivative() const override { return true; }
70  Genfun::Derivative partial( unsigned int i ) const override;
71 
72  AdapterIFunction& operator=( const AdapterIFunction& ) = delete;
73 
74  private:
75  const AIDA::IFunction* m_fun;
77  };
79  FUNCTION_OBJECT_IMP( AdapterIFunction )
80 
81  // ========================================================================
105  // ========================================================================
106  class GAUDI_API Adapter2DoubleFunction : public AbsFunction {
107  public:
109  typedef double ( *Function )( const double, const double );
110 
111  public:
113  FUNCTION_OBJECT_DEF( Adapter2DoubleFunction )
114  public:
119 
120  double operator()( double x ) const override;
121 
122  double operator()( const Argument& x ) const override;
123 
124  unsigned int dimensionality() const override { return 2; }
126  bool hasAnalyticDerivative() const override { return true; }
128  Genfun::Derivative partial( unsigned int i ) const override;
129 
130  public:
131  double operator()( const double x, const double y ) const;
132 
133  // assigmenet operator is disabled
135 
136  private:
137  Function m_func = nullptr;
138  };
140  FUNCTION_OBJECT_IMP( Adapter2DoubleFunction )
141 
142  // ========================================================================
167  // ========================================================================
168  class GAUDI_API Adapter3DoubleFunction : public AbsFunction {
169  public:
171  typedef double ( *Function )( const double, const double, const double );
172 
173  public:
175  FUNCTION_OBJECT_DEF( Adapter3DoubleFunction )
176  public:
181 
182  double operator()( double x ) const override;
183 
184  double operator()( const Argument& x ) const override;
185 
186  unsigned int dimensionality() const override { return 3; }
188  bool hasAnalyticDerivative() const override { return true; }
190  Genfun::Derivative partial( unsigned int i ) const override;
191 
192  public:
193  double operator()( const double x, const double y, const double z ) const;
194 
195  private:
196  // assignment operator is disabled
198 
199  private:
200  Function m_func = nullptr;
201  };
203  FUNCTION_OBJECT_IMP( Adapter3DoubleFunction )
204 
205  // ========================================================================
212  // ========================================================================
213  class GAUDI_API SimpleFunction : public AbsFunction {
214  public:
215  typedef double ( *Function1 )( const double );
216  typedef double ( *Function2 )( const double* );
217  typedef double ( *Function3 )( const std::vector<double>& );
218 
219  public:
221  FUNCTION_OBJECT_DEF( SimpleFunction )
222 
223  public:
227  SimpleFunction( Function1 func );
228 
233  SimpleFunction( Function2 func, const size_t dim );
234 
239  SimpleFunction( Function3 func, const size_t dim );
240 
241  public:
243  unsigned int dimensionality() const override {
244  return detail::dispatch_variant( m_func, []( Function1 ) { return 1ul; },
245  [&]( auto ) { return m_arg.size(); } );
246  }
248  bool hasAnalyticDerivative() const override { return true; }
250  double operator()( double ) const override;
252  double operator()( const Argument& ) const override;
254  Genfun::Derivative partial( unsigned int i ) const override;
255 
256  private:
257  boost::variant<Function1, Function2, Function3> m_func;
259  };
261  FUNCTION_OBJECT_IMP( SimpleFunction )
262 
263  } // namespace GaudiMathImplementation
264 } // end of namespace Genfun
265 
266 #if defined( __clang__ ) || defined( __CLING__ )
267 # pragma clang diagnostic pop
268 #elif defined( __GNUC__ ) && __GNUC__ >= 5
269 # pragma GCC diagnostic pop
270 #endif
271 
272 #endif // GAUDIMATH_FUNADAPTERS_H
auto dispatch_variant
Definition: FunAdapters.h:28
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
Definition: FunAdapters.h:248
mandatory macro from CLHEP/GenericFunctions
Definition: FunAdapters.h:213
Genfun::AbsFunction Function
Definition: GaudiMath.h:23
#define class
Genfun::GaudiMathImplementation::NumericalDerivative Derivative
Definition: GaudiMath.h:26
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
Definition: FunAdapters.h:188
GaudiKernel.
Definition: Fill.h:10
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
Definition: FunAdapters.h:126
PropertyMgr & operator=(const PropertyMgr &)=delete
mandatory macro from CLHEP/GenericFunctions
Definition: FunAdapters.h:106
TupleObj.h GaudiAlg/TupleObj.h namespace with few technical implementations.
boost::variant< Function1, Function2, Function3 > m_func
Definition: FunAdapters.h:257
mandatory macro from CLHEP/GenericFunctions
Definition: FunAdapters.h:168
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26
auto compose(lambda_ts &&...lambdas)
Definition: compose.h:70
CLHEP.
Definition: IEqSolver.h:13
#define GAUDI_API
Definition: Kernel.h:71
T forward(T...args)
unsigned int dimensionality() const override
Definition: FunAdapters.h:65
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
Definition: FunAdapters.h:68
constructor from the IFunction ( see AIDA/IFunction.h)
Definition: FunAdapters.h:49