| The Gaudi Framework v28r2-patches (bc4ad17a)

- 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 <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
25 AdapterIFunction:: AdapterIFunction ( const AdapterIFunction& right )
26 : AbsFunction ( )
27 , m_fun ( right.m_fun )
28 , m_dim ( right.m_dim )
29 , m_arg ( right.m_arg )
30 {}
31
32 AdapterIFunction::~AdapterIFunction() = default;
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
47 Genfun::Derivative AdapterIFunction::partial( unsigned int i ) const
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
58 Adapter2DoubleFunction::Adapter2DoubleFunction
59 ( Adapter2DoubleFunction::Function func )
60 : AbsFunction ( )
61 , m_func ( func )
62 {}
63
64 Adapter2DoubleFunction:: Adapter2DoubleFunction
65 ( const Adapter2DoubleFunction& right )
66 : AbsFunction ( )
67 , m_func ( right.m_func )
68 {}
69
70 Adapter2DoubleFunction::~Adapter2DoubleFunction() = default;
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
86 Genfun::Derivative Adapter2DoubleFunction::partial( unsigned int i ) const
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
97 Adapter3DoubleFunction::Adapter3DoubleFunction
98 ( Adapter3DoubleFunction::Function func )
99 : AbsFunction ( )
100 , m_func ( func )
101 {}
102
103 Adapter3DoubleFunction:: Adapter3DoubleFunction
104 ( const Adapter3DoubleFunction& right )
105 : AbsFunction ( )
106 , m_func ( right.m_func )
107 {}
108
109 Adapter3DoubleFunction::~Adapter3DoubleFunction() = default;
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
126 Genfun::Derivative Adapter3DoubleFunction::partial( unsigned int i ) const
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 // ========================================================================
144 SimpleFunction::SimpleFunction
145 ( SimpleFunction::Function1 func )
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 // ========================================================================
161 SimpleFunction::SimpleFunction
162 ( SimpleFunction::Function2 func ,
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 // ========================================================================
181 SimpleFunction::SimpleFunction
182 ( SimpleFunction::Function3 func ,
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 // ========================================================================
197 SimpleFunction::SimpleFunction
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 // ========================================================================
220 Genfun::Derivative SimpleFunction::partial( unsigned int i ) const
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::GaudiMathImplementation::SimpleFunction::SimpleFunction
SimpleFunction()
Genfun::GaudiMathImplementation::Adapter2DoubleFunction::partial
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:86
Genfun::GaudiMathImplementation::AdapterIFunction::partial
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:47
Genfun::GaudiMathImplementation::SimpleFunction::Function1
double(* Function1)(const double)
Definition: FunAdapters.h:219
Genfun::GaudiMathImplementation::SimpleFunction::partial
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:220
Genfun::GaudiMathImplementation::SimpleFunction::m_func3
Function3 m_func3
Definition: FunAdapters.h:284
Genfun::GaudiMathImplementation::Adapter3DoubleFunction::partial
Genfun::Derivative partial(unsigned int i) const override
Derivatives.
Definition: Adapter.cpp:126
Genfun::GaudiMathImplementation::SimpleFunction::m_arg2
std::unique_ptr< double[]> m_arg2
Definition: FunAdapters.h:282
Genfun::GaudiMathImplementation::SimpleFunction
mandatory macro from CLHEP/GenericFunctions
Definition: FunAdapters.h:216
Genfun::GaudiMathImplementation::SimpleFunction::operator()
double operator()(double) const override
Function value.
Definition: Adapter.cpp:234
std::copy_n
T copy_n(T...args)
GaudiMath::Derivative
Genfun::GaudiMathImplementation::NumericalDerivative Derivative
Definition: GaudiMath.h:29
Genfun::GaudiMathImplementation::AdapterIFunction::m_dim
size_t m_dim
Definition: FunAdapters.h:70
Genfun::GaudiMathImplementation::SimpleFunction::m_func2
Function2 m_func2
Definition: FunAdapters.h:281
Genfun::GaudiMathImplementation::AdapterIFunction::AdapterIFunction
AdapterIFunction()
Genfun::GaudiMathImplementation::Adapter2DoubleFunction::Adapter2DoubleFunction
Adapter2DoubleFunction()
Genfun::GaudiMathImplementation::SimpleFunction::TrivialArg
Definition: FunAdapters.h:223
Genfun::GaudiMathImplementation::AdapterIFunction::operator()
double operator()(double a) const override
Definition: Adapter.cpp:34
Genfun::GaudiMathImplementation::Adapter2DoubleFunction
mandatory macro from CLHEP/GenericFunctions
Definition: FunAdapters.h:101
Genfun::GaudiMathImplementation::SimpleFunction::m_arg3
std::vector< double > m_arg3
Definition: FunAdapters.h:285
Genfun::GaudiMathImplementation::Adapter2DoubleFunction::m_func
Function m_func
Definition: FunAdapters.h:135
Genfun::GaudiMathImplementation::SimpleFunction::VectorArg
Definition: FunAdapters.h:223
GaudiPluginService.cpluginsvc.func
func
Definition: cpluginsvc.py:218
Genfun::GaudiMathImplementation::Adapter3DoubleFunction::m_func
Function m_func
Definition: FunAdapters.h:203
Genfun::GaudiMathImplementation::SimpleFunction::ArrayArg
Definition: FunAdapters.h:223
Genfun::GaudiMathImplementation::SimpleFunction::m_DIM
size_t m_DIM
Definition: FunAdapters.h:277
Genfun::GaudiMathImplementation::Adapter3DoubleFunction
mandatory macro from CLHEP/GenericFunctions
Definition: FunAdapters.h:166
std::unique_ptr::get
T get(T...args)
Genfun::GaudiMathImplementation::AdapterIFunction::m_fun
const AIDA::IFunction * m_fun
Definition: FunAdapters.h:69
Genfun::GaudiMathImplementation::SimpleFunction::m_case
Case m_case
Definition: FunAdapters.h:276
Genfun::GaudiMathImplementation::AdapterIFunction::m_arg
std::vector< double > m_arg
Definition: FunAdapters.h:71
fun
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26
Genfun::GaudiMathImplementation::SimpleFunction::Function2
double(* Function2)(const double *)
Definition: FunAdapters.h:220
Genfun::GaudiMathImplementation::AdapterIFunction::~AdapterIFunction
~AdapterIFunction() override
desctructor
std::fill_n
T fill_n(T...args)
Genfun::GaudiMathImplementation::SimpleFunction::Function3
double(* Function3)(const std::vector< double > &)
Definition: FunAdapters.h:221
Genfun::GaudiMathImplementation::Adapter2DoubleFunction::Function
double(* Function)(const double, const double)
the actual type of the function "to be adapted"
Definition: FunAdapters.h:105
Genfun::GaudiMathImplementation::SimpleFunction::m_func1
Function1 m_func1
Definition: FunAdapters.h:279
Genfun
CLHEP.
Definition: IEqSolver.h:13
Genfun::GaudiMathImplementation::Adapter3DoubleFunction::~Adapter3DoubleFunction
~Adapter3DoubleFunction() override
destructor
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:170
GaudiMath::Constant
Genfun::GaudiMathImplementation::Constant Constant
Definition: GaudiMath.h:27
GaudiMath.h
Genfun::GaudiMathImplementation::Adapter3DoubleFunction::Adapter3DoubleFunction
Adapter3DoubleFunction()
Genfun::GaudiMathImplementation::AdapterIFunction
constructor from the IFunction ( see AIDA/IFunction.h)
Definition: FunAdapters.h:39
Genfun::GaudiMathImplementation::Adapter2DoubleFunction::~Adapter2DoubleFunction
~Adapter2DoubleFunction() override
destructor