The Gaudi Framework  v30r3 (a5ef0a68)
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 <cassert>
12 #include <cstring>
13 
14 namespace Genfun
15 {
16  namespace GaudiMathImplementation
17  {
18 
19  AdapterIFunction::AdapterIFunction( const AIDA::IFunction& fun ) : m_fun( &fun ), m_arg( fun.dimension(), 0 ) {}
20 
21  double AdapterIFunction::operator()( double x ) const
22  {
23  assert( begin( m_arg ) != end( m_arg ) );
24  m_arg[0] = x;
25  std::fill( std::next( begin( m_arg ) ), end( m_arg ), 0.0 );
26  return m_fun->value( m_arg );
27  }
28 
29  double AdapterIFunction::operator()( const Genfun::Argument& x ) const
30  {
31  for ( size_t i = 0; i < m_arg.size(); ++i ) {
32  m_arg[i] = x[i];
33  }
34  return m_fun->value( m_arg );
35  }
36 
38  {
39  if ( i >= m_arg.size() ) {
40  const AbsFunction& aux = GaudiMath::Constant( 0, m_arg.size() );
41  return Genfun::FunctionNoop( &aux );
42  };
43  const AbsFunction& aux = GaudiMath::Derivative( *this, i );
44  return Genfun::FunctionNoop( &aux );
45  }
46 
48  : AbsFunction(), m_func( func )
49  {
50  }
51 
52  double Adapter2DoubleFunction::operator()( double x ) const { return m_func( x, 0 ); }
53 
54  double Adapter2DoubleFunction::operator()( const Genfun::Argument& x ) const { return m_func( x[0], x[1] ); }
55 
56  double Adapter2DoubleFunction::operator()( const double x, const double y ) const { return m_func( x, y ); }
57 
60  {
61  if ( i >= 2 ) {
62  GaudiMath::Constant aux{0, 2};
63  return Genfun::FunctionNoop( &aux );
64  }
65  GaudiMath::Derivative aux{*this, i};
66  return Genfun::FunctionNoop( &aux );
67  }
68 
70 
71  double Adapter3DoubleFunction::operator()( double x ) const { return m_func( x, 0, 0 ); }
72 
73  double Adapter3DoubleFunction::operator()( const Genfun::Argument& x ) const { return m_func( x[0], x[1], x[2] ); }
74 
75  double Adapter3DoubleFunction::operator()( const double x, const double y, const double z ) const
76  {
77  return m_func( x, y, z );
78  }
79 
82  {
83  if ( i >= 3 ) {
84  GaudiMath::Constant aux{0, 3};
85  return Genfun::FunctionNoop( &aux );
86  }
87  GaudiMath::Derivative aux{*this, i};
88  return Genfun::FunctionNoop( &aux );
89  }
90 
91  // ========================================================================
92 
93  // =======================================================================
97  // ========================================================================
99  // ========================================================================
100 
101  // ========================================================================
106  // ========================================================================
108  {
109  }
110  // ========================================================================
111 
112  // ========================================================================
117  // ========================================================================
119  {
120  }
121  // ========================================================================
122 
123  // ========================================================================
125  // ========================================================================
127  {
128  const auto dim = dimensionality();
129  if ( i >= dim ) {
130  GaudiMath::Constant aux{0, dim};
131  return Genfun::FunctionNoop( &aux );
132  }
133  GaudiMath::Derivative aux{*this, i};
134  return Genfun::FunctionNoop( &aux );
135  }
136 
137  // ========================================================================
139  // ========================================================================
140  double SimpleFunction::operator()( double value ) const
141  {
142  return detail::dispatch_variant( m_func, [&]( const Function1& fun ) { return ( *fun )( value ); },
143  [&]( const Function2& fun ) {
144  m_arg[0] = value;
145  std::fill( std::next( m_arg.begin() ), m_arg.end(), 0.0 );
146  return ( *fun )( m_arg.data() );
147  },
148  [&]( const Function3& fun ) {
149  m_arg[0] = value;
150  std::fill( std::next( m_arg.begin() ), m_arg.end(), 0.0 );
151  return ( *fun )( m_arg );
152  } );
153  }
154  // ========================================================================
155 
156  // ========================================================================
158  // ========================================================================
159  double SimpleFunction::operator()( const Argument& argument ) const
160  {
161  return detail::dispatch_variant( m_func, [&]( const Function1& f ) { return ( *f )( argument[0] ); },
162  [&]( const Function2& f ) {
163  for ( size_t i = 0; i < m_arg.size(); ++i ) {
164  m_arg[i] = argument[i];
165  }
166  return ( *f )( m_arg.data() );
167  },
168  [&]( const Function3& f ) {
169  for ( size_t i = 0; i < m_arg.size(); ++i ) {
170  m_arg[i] = argument[i];
171  }
172  return ( *f )( m_arg );
173  } );
174  }
175 
176  } // end of namespace GaudiMathImplementation
177 } // end of namespace Genfun
178 
179 // ============================================================================
180 // The END
181 // ============================================================================
double(* Function)(const double, const double)
the actual type of the function "to be adapted"
Definition: FunAdapters.h:115
Fixed constant function.
Definition: Constant.h:31
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:59
double(* Function3)(const std::vector< double > &)
Definition: FunAdapters.h:225
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:37
auto dispatch_variant
Definition: FunAdapters.h:29
unsigned int dimensionality() const override
dimensionality of the problem
Definition: FunAdapters.h:251
double operator()(double x) const override
Definition: Adapter.cpp:52
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:126
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:81
double operator()(double) const override
Function value.
Definition: Adapter.cpp:140
AdapterIFunction(const AIDA::IFunction &fun)
mandatory macro from CLHEP/GenericFunctions
Definition: Adapter.cpp:19
T end(T...args)
Genfun::GaudiMathImplementation::NumericalDerivative Derivative
Definition: GaudiMath.h:27
double operator()(double a) const override
Definition: Adapter.cpp:21
T data(T...args)
T next(T...args)
SimpleFunction(Function1 func)
From CLHEP/GenericFunctions.
Definition: Adapter.cpp:98
boost::variant< Function1, Function2, Function3 > m_func
Definition: FunAdapters.h:266
Numerical derivative (using GSL adaptive numerical differentiation)
double operator()(double x) const override
Definition: Adapter.cpp:71
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:47
Adapter3DoubleFunction(Function func)
mandatory macro from CLHEP/GenericFunctions
Definition: Adapter.cpp:69
T fill(T...args)
AttribStringParser::Iterator begin(const AttribStringParser &parser)
double(* Function)(const double, const double, const double)
the actual type of the function "to be adapted"
Definition: FunAdapters.h:178
Genfun::GaudiMathImplementation::Constant Constant
Definition: GaudiMath.h:26