Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
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 <cassert>
12 #include <cstring>
13 
14 namespace Genfun {
15  namespace GaudiMathImplementation {
16 
17  AdapterIFunction::AdapterIFunction( const AIDA::IFunction& fun ) : m_fun( &fun ), m_arg( fun.dimension(), 0 ) {}
18 
19  double AdapterIFunction::operator()( double x ) const {
20  assert( begin( m_arg ) != end( m_arg ) );
21  m_arg[0] = x;
22  std::fill( std::next( begin( m_arg ) ), end( m_arg ), 0.0 );
23  return m_fun->value( m_arg );
24  }
25 
26  double AdapterIFunction::operator()( const Genfun::Argument& x ) const {
27  for ( size_t i = 0; i < m_arg.size(); ++i ) { m_arg[i] = x[i]; }
28  return m_fun->value( m_arg );
29  }
30 
32  if ( i >= m_arg.size() ) {
33  const AbsFunction& aux = GaudiMath::Constant( 0, m_arg.size() );
34  return Genfun::FunctionNoop( &aux );
35  };
36  const AbsFunction& aux = GaudiMath::Derivative( *this, i );
37  return Genfun::FunctionNoop( &aux );
38  }
39 
41  : AbsFunction(), m_func( func ) {}
42 
43  double Adapter2DoubleFunction::operator()( double x ) const { return m_func( x, 0 ); }
44 
45  double Adapter2DoubleFunction::operator()( const Genfun::Argument& x ) const { return m_func( x[0], x[1] ); }
46 
47  double Adapter2DoubleFunction::operator()( const double x, const double y ) const { return m_func( x, y ); }
48 
51  if ( i >= 2 ) {
52  GaudiMath::Constant aux{0, 2};
53  return Genfun::FunctionNoop( &aux );
54  }
55  GaudiMath::Derivative aux{*this, i};
56  return Genfun::FunctionNoop( &aux );
57  }
58 
60 
61  double Adapter3DoubleFunction::operator()( double x ) const { return m_func( x, 0, 0 ); }
62 
63  double Adapter3DoubleFunction::operator()( const Genfun::Argument& x ) const { return m_func( x[0], x[1], x[2] ); }
64 
65  double Adapter3DoubleFunction::operator()( const double x, const double y, const double z ) const {
66  return m_func( x, y, z );
67  }
68 
71  if ( i >= 3 ) {
72  GaudiMath::Constant aux{0, 3};
73  return Genfun::FunctionNoop( &aux );
74  }
75  GaudiMath::Derivative aux{*this, i};
76  return Genfun::FunctionNoop( &aux );
77  }
78 
79  // ========================================================================
80 
81  // =======================================================================
85  // ========================================================================
87  // ========================================================================
88 
89  // ========================================================================
94  // ========================================================================
96  : m_func( func ), m_arg( dim, 0 ) {}
97  // ========================================================================
98 
99  // ========================================================================
104  // ========================================================================
106  : m_func( func ), m_arg( dim, 0 ) {}
107  // ========================================================================
108 
109  // ========================================================================
111  // ========================================================================
112  Genfun::Derivative SimpleFunction::partial( unsigned int i ) const {
113  const auto dim = dimensionality();
114  if ( i >= dim ) {
115  GaudiMath::Constant aux{0, dim};
116  return Genfun::FunctionNoop( &aux );
117  }
118  GaudiMath::Derivative aux{*this, i};
119  return Genfun::FunctionNoop( &aux );
120  }
121 
122  // ========================================================================
124  // ========================================================================
125  double SimpleFunction::operator()( double value ) const {
126  return ::detail::dispatch_variant( m_func, [&]( const Function1& fun ) { return ( *fun )( value ); },
127  [&]( const Function2& fun ) {
128  m_arg[0] = value;
129  std::fill( std::next( m_arg.begin() ), m_arg.end(), 0.0 );
130  return ( *fun )( m_arg.data() );
131  },
132  [&]( const Function3& fun ) {
133  m_arg[0] = value;
134  std::fill( std::next( m_arg.begin() ), m_arg.end(), 0.0 );
135  return ( *fun )( m_arg );
136  } );
137  }
138  // ========================================================================
139 
140  // ========================================================================
142  // ========================================================================
143  double SimpleFunction::operator()( const Argument& argument ) const {
144  return ::detail::dispatch_variant( m_func, [&]( const Function1& f ) { return ( *f )( argument[0] ); },
145  [&]( const Function2& f ) {
146  for ( size_t i = 0; i < m_arg.size(); ++i ) { m_arg[i] = argument[i]; }
147  return ( *f )( m_arg.data() );
148  },
149  [&]( const Function3& f ) {
150  for ( size_t i = 0; i < m_arg.size(); ++i ) { m_arg[i] = argument[i]; }
151  return ( *f )( m_arg );
152  } );
153  }
154 
155  } // end of namespace GaudiMathImplementation
156 } // end of namespace Genfun
157 
158 // ============================================================================
159 // The END
160 // ============================================================================
double(* Function)(const double, const double)
the actual type of the function "to be adapted"
Definition: FunAdapters.h:109
Fixed constant function.
Definition: Constant.h:30
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:50
double(* Function3)(const std::vector< double > &)
Definition: FunAdapters.h:217
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:31
auto dispatch_variant
Definition: FunAdapters.h:28
unsigned int dimensionality() const override
dimensionality of the problem
Definition: FunAdapters.h:243
double operator()(double x) const override
Definition: Adapter.cpp:43
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:112
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:70
double operator()(double) const override
Function value.
Definition: Adapter.cpp:125
AdapterIFunction(const AIDA::IFunction &fun)
mandatory macro from CLHEP/GenericFunctions
Definition: Adapter.cpp:17
T end(T...args)
Genfun::GaudiMathImplementation::NumericalDerivative Derivative
Definition: GaudiMath.h:26
double operator()(double a) const override
Definition: Adapter.cpp:19
T data(T...args)
T next(T...args)
SimpleFunction(Function1 func)
From CLHEP/GenericFunctions.
Definition: Adapter.cpp:86
boost::variant< Function1, Function2, Function3 > m_func
Definition: FunAdapters.h:257
Numerical derivative (using GSL adaptive numerical differentiation)
double operator()(double x) const override
Definition: Adapter.cpp:61
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:40
Adapter3DoubleFunction(Function func)
mandatory macro from CLHEP/GenericFunctions
Definition: Adapter.cpp:59
CLHEP.
Definition: IEqSolver.h:13
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:171
Genfun::GaudiMathImplementation::Constant Constant
Definition: GaudiMath.h:25