All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
13 namespace Genfun
14 {
15  namespace GaudiMathImplementation
16  {
17 
18  AdapterIFunction::AdapterIFunction ( const AIDA::IFunction& fun)
19  : AbsFunction ( )
20  , m_fun ( &fun )
21  , m_dim ( fun.dimension() )
22  , m_arg ( fun.dimension() , 0 )
23  {}
24 
26  : AbsFunction ( )
27  , m_fun ( right.m_fun )
28  , m_dim ( right.m_dim )
29  , m_arg ( right.m_arg )
30  {}
31 
33 
34  double AdapterIFunction::operator() ( double x ) const
35  {
36  for ( size_t i = 0; i < m_dim; ++i ) { m_arg[i] = 0.0 ; }
37  m_arg[0] = x ;
38  return m_fun -> value ( m_arg ) ;
39  }
40 
41  double AdapterIFunction::operator() ( const Genfun::Argument& x ) const
42  {
43  for ( size_t i = 0; i < m_dim; ++i ) { m_arg[i] = x[i] ; }
44  return m_fun -> value ( m_arg ) ;
45  }
46 
48  {
49  if ( i >= m_dim )
50  {
51  const AbsFunction& aux = GaudiMath::Constant( 0 , m_dim ) ;
52  return Genfun::FunctionNoop( &aux ) ;
53  };
54  const AbsFunction& aux = GaudiMath::Derivative( *this , i ) ;
55  return Genfun::FunctionNoop ( &aux ) ;
56  }
57 
60  : AbsFunction ( )
61  , m_func ( func )
62  {}
63 
65  ( const Adapter2DoubleFunction& right )
66  : AbsFunction ( )
67  , m_func ( right.m_func )
68  {}
69 
71 
72  double Adapter2DoubleFunction::operator()
73  ( double x ) const
74  { return m_func ( x , 0 ) ; }
75 
76  double Adapter2DoubleFunction::operator()
77  ( const Genfun::Argument& x ) const
78  { return m_func ( x[0] , x[1] ) ; }
79 
80  double Adapter2DoubleFunction::operator()
81  ( const double x ,
82  const double y ) const
83  { return m_func ( x , y ) ; }
84 
87  {
88  if ( i >= 2 )
89  {
90  const AbsFunction& aux = GaudiMath::Constant( 0 , 2 ) ;
91  return Genfun::FunctionNoop( &aux ) ;
92  };
93  const AbsFunction& aux = GaudiMath::Derivative( *this , i ) ;
94  return Genfun::FunctionNoop ( &aux ) ;
95  }
96 
99  : AbsFunction ( )
100  , m_func ( func )
101  {}
102 
104  ( const Adapter3DoubleFunction& right )
105  : AbsFunction ( )
106  , m_func ( right.m_func )
107  {}
108 
110 
111  double Adapter3DoubleFunction::operator()
112  ( double x ) const
113  { return m_func ( x , 0 , 0 ) ; }
114 
115  double Adapter3DoubleFunction::operator()
116  ( const Genfun::Argument& x ) const
117  { return m_func ( x[0] , x[1] , x[2] ) ; }
118 
119  double Adapter3DoubleFunction::operator()
120  ( const double x ,
121  const double y ,
122  const double z ) const
123  { return m_func ( x , y , z ) ; }
124 
127  {
128  if ( i >= 3 )
129  {
130  const AbsFunction& aux = GaudiMath::Constant( 0 , 3 ) ;
131  return Genfun::FunctionNoop( &aux ) ;
132  };
133  const AbsFunction& aux = GaudiMath::Derivative( *this , i ) ;
134  return Genfun::FunctionNoop ( &aux ) ;
135  }
136 
137  // ========================================================================
138 
139  // =======================================================================
143  // ========================================================================
146  : AbsFunction ()
147  , m_case ( SimpleFunction::TrivialArg )
148  , m_DIM ( 1 )
149  , m_func1 ( func )
150  , m_func2 ( nullptr )
151  , m_func3 ( nullptr )
152  {}
153  // ========================================================================
154 
155  // ========================================================================
160  // ========================================================================
163  const size_t dim )
164  : AbsFunction ()
165  , m_case ( SimpleFunction::ArrayArg )
166  , m_DIM ( dim )
167  , m_func1 ( nullptr )
168  , m_func2 ( func )
169  , m_arg2 ( new double[dim] )
170  , m_func3 ( nullptr )
171  {
172  }
173  // ========================================================================
174 
175  // ========================================================================
180  // ========================================================================
183  const size_t dim )
184  : AbsFunction ()
185  , m_case ( SimpleFunction::VectorArg )
186  , m_DIM ( dim )
187  , m_func1 ( nullptr )
188  , m_func2 ( nullptr )
189  , m_func3 ( func )
190  , m_arg3 ( dim , 0 )
191  {}
192  // ========================================================================
193 
194  // ========================================================================
196  // ========================================================================
198  ( const SimpleFunction& right )
199  : AbsFunction ()
200  , m_case ( right.m_case )
201  , m_DIM ( right.m_DIM )
202  , m_func1 ( right.m_func1 )
203  , m_func2 ( right.m_func2 )
204  , m_func3 ( right.m_func3 )
205  , m_arg3 ( right.m_arg3 )
206  {
207  if ( right.m_arg2 )
208  {
209  m_arg2.reset( new double[m_DIM] );
210  std::copy_n(right.m_arg2.get(), m_DIM, m_arg2.get());
211  }
212  }
213  // ========================================================================
214 
215  // ========================================================================
216 
217  // ========================================================================
219  // ========================================================================
221  {
222  if ( i >= m_DIM )
223  {
224  const AbsFunction& aux = GaudiMath::Constant( 0 , m_DIM ) ;
225  return Genfun::FunctionNoop( &aux ) ;
226  }
227  const AbsFunction& aux = GaudiMath::Derivative( *this , i ) ;
228  return Genfun::FunctionNoop( &aux );
229  }
230 
231  // ========================================================================
233  // ========================================================================
234  double SimpleFunction::operator() ( double value ) const
235  {
236  double result = 0 ;
237  switch ( m_case )
238  {
239  case TrivialArg :
240  result = (*m_func1) ( value ) ; break ;
241  case ArrayArg :
242  std::fill_n( m_arg2.get() , m_DIM , 0.0 );
243  m_arg2[0] = value ;
244  result = (*m_func2) ( m_arg2.get() ) ; break ;
245  case VectorArg :
246  std::fill ( m_arg3.begin () , m_arg3.end () , 0.0 );
247  m_arg3[0] = value ;
248  result = (*m_func3) ( m_arg3 ) ; break ;
249  default:
250  break ;
251  };
252  return result ;
253  }
254  // ========================================================================
255 
256  // ========================================================================
258  // ========================================================================
259  double SimpleFunction::operator() ( const Argument& argument ) const
260  {
261  double result = 0 ;
262  switch ( m_case )
263  {
264  case TrivialArg :
265  result = (*m_func1) ( argument[0] ) ; break ;
266  case ArrayArg :
267  for( size_t i = 0 ; i < m_DIM ; ++i ) { m_arg2[i] = argument[i] ; }
268  return (*m_func2)( m_arg2.get() ) ; ; break ;
269  case VectorArg :
270  for( size_t i = 0 ; i < m_DIM ; ++i ) { m_arg3[i] = argument[i] ; }
271  result = (*m_func3) ( m_arg3 ) ; break ;
272  default:
273  break ;
274  }
275  return result ;
276  }
277 
278  } // end of namespace GaudiMathImplementation
279 } // end of namespace Genfun
280 
281 
282 // ============================================================================
283 // The END
284 // ============================================================================
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:86
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:47
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:220
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:126
mandatory macro from CLHEP/GenericFunctions
Definition: FunAdapters.h:216
double operator()(double) const override
Function value.
Definition: Adapter.cpp:234
T copy_n(T...args)
Genfun::GaudiMathImplementation::NumericalDerivative Derivative
Definition: GaudiMath.h:29
double operator()(double a) const override
Definition: Adapter.cpp:34
mandatory macro from CLHEP/GenericFunctions
Definition: FunAdapters.h:101
mandatory macro from CLHEP/GenericFunctions
Definition: FunAdapters.h:166
T get(T...args)
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26
T fill_n(T...args)
double(* Function3)(const std::vector< double > &)
Definition: FunAdapters.h:221
double(* Function)(const double, const double)
the actual type of the function "to be adapted"
Definition: FunAdapters.h:105
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:170
Genfun::GaudiMathImplementation::Constant Constant
Definition: GaudiMath.h:27
constructor from the IFunction ( see AIDA/IFunction.h)
Definition: FunAdapters.h:39