The Gaudi Framework  v28r3 (cc1cf868)
Adapter.cpp
Go to the documentation of this file.
1 // Include files
2 // ============================================================================
3 // GaudiMath
4 // ============================================================================
5 #include "GaudiMath/GaudiMath.h"
6 // ============================================================================
7 // AIDA
8 // ============================================================================
9 #include "AIDA/IFunction.h"
10 // ============================================================================
11 #include <cstring>
12 #include <cassert>
13 
14 
15 namespace Genfun
16 {
17  namespace GaudiMathImplementation
18  {
19 
20  AdapterIFunction::AdapterIFunction ( const AIDA::IFunction& fun)
21  : m_fun ( &fun )
22  , m_arg ( fun.dimension() , 0 )
23  {}
24 
25  double AdapterIFunction::operator() ( double x ) const
26  {
27  assert(begin(m_arg)!=end(m_arg));
28  m_arg[0] = x ;
29  std::fill( std::next(begin(m_arg)), end(m_arg), 0.0 );
30  return m_fun -> value ( m_arg ) ;
31  }
32 
33  double AdapterIFunction::operator() ( const Genfun::Argument& x ) const
34  {
35  for ( size_t i = 0; i < m_arg.size(); ++i ) { m_arg[i] = x[i] ; }
36  return m_fun -> value ( m_arg ) ;
37  }
38 
40  {
41  if ( i >= m_arg.size() ) {
42  const AbsFunction& aux = GaudiMath::Constant( 0 , m_arg.size() ) ;
43  return Genfun::FunctionNoop( &aux ) ;
44  };
45  const AbsFunction& aux = GaudiMath::Derivative( *this , i ) ;
46  return Genfun::FunctionNoop ( &aux ) ;
47  }
48 
51  : AbsFunction()
52  , m_func ( func )
53  {}
54 
55 
56  double Adapter2DoubleFunction::operator()( double x ) const
57  { return m_func ( x , 0 ) ; }
58 
59  double Adapter2DoubleFunction::operator()( const Genfun::Argument& x ) const
60  { return m_func ( x[0] , x[1] ) ; }
61 
62  double Adapter2DoubleFunction::operator()( const double x ,
63  const double y ) const
64  { return m_func ( x , y ) ; }
65 
68  {
69  if ( i>=2 ) {
70  GaudiMath::Constant aux{ 0 , 2 };
71  return Genfun::FunctionNoop( &aux ) ;
72  }
73  GaudiMath::Derivative aux{ *this , i };
74  return Genfun::FunctionNoop( &aux ) ;
75 
76  }
77 
80  : m_func ( func )
81  {}
82 
83  double Adapter3DoubleFunction::operator()( double x ) const
84  { return m_func ( x , 0 , 0 ) ; }
85 
86  double Adapter3DoubleFunction::operator()( const Genfun::Argument& x ) const
87  { return m_func ( x[0] , x[1] , x[2] ) ; }
88 
89  double Adapter3DoubleFunction::operator()( const double x ,
90  const double y ,
91  const double z ) const
92  { return m_func ( x , y , z ) ; }
93 
96  {
97  if ( i>=3 ) {
98  GaudiMath::Constant aux{ 0 , 3 };
99  return Genfun::FunctionNoop ( &aux ) ;
100  }
101  GaudiMath::Derivative aux{ *this , i };
102  return Genfun::FunctionNoop ( &aux ) ;
103  }
104 
105  // ========================================================================
106 
107  // =======================================================================
111  // ========================================================================
114  : m_func( func )
115  {}
116  // ========================================================================
117 
118  // ========================================================================
123  // ========================================================================
126  const size_t dim )
127  : m_func ( func )
128  , m_arg ( dim, 0 )
129  {}
130  // ========================================================================
131 
132  // ========================================================================
137  // ========================================================================
140  const size_t dim )
141  : m_func ( func )
142  , m_arg ( dim , 0 )
143  {}
144  // ========================================================================
145 
146  // ========================================================================
148  // ========================================================================
150  {
151  const auto dim = dimensionality();
152  if ( i>= dim ) {
153  GaudiMath::Constant aux{ 0 , dim };
154  return Genfun::FunctionNoop( &aux ) ;
155  }
156  GaudiMath::Derivative aux{ *this , i };
157  return Genfun::FunctionNoop( &aux ) ;
158  }
159 
160  // ========================================================================
162  // ========================================================================
163  double SimpleFunction::operator() ( double value ) const
164  {
165  return detail::dispatch_variant( m_func,
166  [&](const Function1& fun) { return (*fun)(value); },
167  [&](const Function2& fun) { m_arg[0] = value ;
168  std::fill( std::next(m_arg.begin()) , m_arg.end() , 0.0 );
169  return (*fun) ( m_arg.data() ) ; },
170  [&](const Function3& fun) { m_arg[0] = value ;
171  std::fill ( std::next(m_arg.begin()) , m_arg.end() , 0.0 );
172  return (*fun) ( m_arg ) ; } );
173  }
174  // ========================================================================
175 
176  // ========================================================================
178  // ========================================================================
179  double SimpleFunction::operator() ( const Argument& argument ) const
180  {
181  return detail::dispatch_variant( m_func,
182  [&](const Function1& f) { return (*f)(argument[0]); },
183  [&](const Function2& f) { for ( size_t i = 0; i < m_arg.size(); ++i ) { m_arg[i] = argument[i] ; }
184  return (*f)( m_arg.data() ) ; },
185  [&](const Function3& f) { for ( size_t i = 0; i < m_arg.size(); ++i ) { m_arg[i] = argument[i] ; }
186  return (*f)( m_arg ); } );
187  }
188 
189  } // end of namespace GaudiMathImplementation
190 } // end of namespace Genfun
191 
192 
193 // ============================================================================
194 // The END
195 // ============================================================================
Fixed constant function.
Definition: Constant.h:31
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:67
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:39
auto dispatch_variant
Definition: FunAdapters.h:70
double operator()(double x) const override
Definition: Adapter.cpp:56
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:149
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:95
double operator()(double) const override
Function value.
Definition: Adapter.cpp:163
AdapterIFunction(const AIDA::IFunction &fun)
mandatory macro from CLHEP/GenericFunctions
Definition: Adapter.cpp:20
T end(T...args)
Genfun::GaudiMathImplementation::NumericalDerivative Derivative
Definition: GaudiMath.h:29
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:48
double operator()(double a) const override
Definition: Adapter.cpp:25
T data(T...args)
T next(T...args)
SimpleFunction(Function1 func)
From CLHEP/GenericFunctions.
Definition: Adapter.cpp:113
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:50
Numerical derivative (using GSL adaptive numerical differentiation)
double operator()(double x) const override
Definition: Adapter.cpp:83
T size(T...args)
T begin(T...args)
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26
Adapter2DoubleFunction(Function func)
mandatory macro from CLHEP/GenericFunctions
Definition: Adapter.cpp:50
double(* Function3)(const std::vector< double > &)
Definition: FunAdapters.h:261
double(* Function)(const double, const double)
the actual type of the function "to be adapted"
Definition: FunAdapters.h:153
Adapter3DoubleFunction(Function func)
mandatory macro from CLHEP/GenericFunctions
Definition: Adapter.cpp:79
CLHEP.
Definition: IEqSolver.h:13
T fill(T...args)
double(* Function)(const double, const double, const double)
the actual type of the function "to be adapted"
Definition: FunAdapters.h:214
Genfun::GaudiMathImplementation::Constant Constant
Definition: GaudiMath.h:27
unsigned int dimensionality() const override
Definition: FunAdapters.h:109