| The Gaudi Framework v29r1 (5cd95fa2)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
37 Genfun::Derivative AdapterIFunction::partial( unsigned int i ) const
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
47 Adapter2DoubleFunction::Adapter2DoubleFunction( Adapter2DoubleFunction::Function func )
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
59 Genfun::Derivative Adapter2DoubleFunction::partial( unsigned int i ) const
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
69 Adapter3DoubleFunction::Adapter3DoubleFunction( Adapter3DoubleFunction::Function func ) : m_func( func ) {}
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
81 Genfun::Derivative Adapter3DoubleFunction::partial( unsigned int i ) const
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 // ========================================================================
98 SimpleFunction::SimpleFunction( SimpleFunction::Function1 func ) : m_func( func ) {}
99 // ========================================================================
100
101 // ========================================================================
106 // ========================================================================
107 SimpleFunction::SimpleFunction( SimpleFunction::Function2 func, const size_t dim ) : m_func( func ), m_arg( dim, 0 )
108 {
109 }
110 // ========================================================================
111
112 // ========================================================================
117 // ========================================================================
118 SimpleFunction::SimpleFunction( SimpleFunction::Function3 func, const size_t dim ) : m_func( func ), m_arg( dim, 0 )
119 {
120 }
121 // ========================================================================
122
123 // ========================================================================
125 // ========================================================================
126 Genfun::Derivative SimpleFunction::partial( unsigned int i ) const
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 // ============================================================================
Genfun::GaudiMathImplementation::Adapter2DoubleFunction::Function
double(* Function)(const double, const double)
the actual type of the function "to be adapted"
Definition: FunAdapters.h:163
Genfun::GaudiMathImplementation::Constant
Fixed constant function.
Definition: Constant.h:31
Genfun::GaudiMathImplementation::Adapter2DoubleFunction::partial
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:59
Genfun::GaudiMathImplementation::SimpleFunction::Function3
double(* Function3)(const std::vector< double > &)
Definition: FunAdapters.h:273
Genfun::GaudiMathImplementation::AdapterIFunction::partial
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:37
detail::dispatch_variant
auto dispatch_variant
Definition: FunAdapters.h:77
Genfun::GaudiMathImplementation::SimpleFunction::dimensionality
unsigned int dimensionality() const override
dimensionality of the problem
Definition: FunAdapters.h:299
Genfun::GaudiMathImplementation::Adapter2DoubleFunction::operator()
double operator()(double x) const override
Definition: Adapter.cpp:52
Genfun::GaudiMathImplementation::SimpleFunction::partial
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:126
Genfun::GaudiMathImplementation::Adapter3DoubleFunction::partial
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:81
Genfun::GaudiMathImplementation::SimpleFunction::operator()
double operator()(double) const override
Function value.
Definition: Adapter.cpp:140
Genfun::GaudiMathImplementation::AdapterIFunction::AdapterIFunction
AdapterIFunction(const AIDA::IFunction &fun)
mandatory macro from CLHEP/GenericFunctions
Definition: Adapter.cpp:19
std::vector::end
T end(T...args)
GaudiMath::Derivative
Genfun::GaudiMathImplementation::NumericalDerivative Derivative
Definition: GaudiMath.h:27
begin
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:58
Genfun::GaudiMathImplementation::AdapterIFunction::operator()
double operator()(double a) const override
Definition: Adapter.cpp:21
Genfun::GaudiMathImplementation::SimpleFunction::Function1
double(* Function1)(const double)
Definition: FunAdapters.h:271
std::vector::data
T data(T...args)
Genfun::GaudiMathImplementation::Adapter2DoubleFunction::m_func
Function m_func
Definition: FunAdapters.h:191
Genfun::GaudiMathImplementation::SimpleFunction::m_arg
std::vector< double > m_arg
Definition: FunAdapters.h:315
GaudiPluginService.cpluginsvc.func
func
Definition: cpluginsvc.py:229
std::next
T next(T...args)
Genfun::GaudiMathImplementation::Adapter3DoubleFunction::m_func
Function m_func
Definition: FunAdapters.h:255
Genfun::GaudiMathImplementation::SimpleFunction::SimpleFunction
SimpleFunction(Function1 func)
From CLHEP/GenericFunctions.
Definition: Adapter.cpp:98
Genfun::GaudiMathImplementation::SimpleFunction::m_func
boost::variant< Function1, Function2, Function3 > m_func
Definition: FunAdapters.h:314
end
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:64
Genfun::GaudiMathImplementation::NumericalDerivative
Numerical derivative (using GSL adaptive numerical differentiation)
Definition: NumericalDerivative.h:42
Genfun::GaudiMathImplementation::Adapter3DoubleFunction::operator()
double operator()(double x) const override
Definition: Adapter.cpp:71
Genfun::GaudiMathImplementation::AdapterIFunction::m_fun
const AIDA::IFunction * m_fun
Definition: FunAdapters.h:128
std::vector::size
T size(T...args)
std::vector::begin
T begin(T...args)
Genfun::GaudiMathImplementation::AdapterIFunction::m_arg
std::vector< double > m_arg
Definition: FunAdapters.h:129
fun
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26
Genfun::GaudiMathImplementation::Adapter2DoubleFunction::Adapter2DoubleFunction
Adapter2DoubleFunction(Function func)
mandatory macro from CLHEP/GenericFunctions
Definition: Adapter.cpp:47
Genfun::GaudiMathImplementation::Adapter3DoubleFunction::Adapter3DoubleFunction
Adapter3DoubleFunction(Function func)
mandatory macro from CLHEP/GenericFunctions
Definition: Adapter.cpp:69
Genfun
CLHEP.
Definition: IEqSolver.h:13
std::fill
T fill(T...args)
Genfun::GaudiMathImplementation::Adapter3DoubleFunction::Function
double(* Function)(const double, const double, const double)
the actual type of the function "to be adapted"
Definition: FunAdapters.h:226
GaudiMath::Constant
Genfun::GaudiMathImplementation::Constant Constant
Definition: GaudiMath.h:26
GaudiMath.h
Genfun::GaudiMathImplementation::SimpleFunction::Function2
double(* Function2)(const double *)
Definition: FunAdapters.h:272