| The Gaudi Framework v27r1

- 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 FUNCTION_OBJECT_IMP( AdapterIFunction )
19
20 AdapterIFunction::AdapterIFunction ( const AIDA::IFunction& fun)
21 : AbsFunction ( )
22 , m_fun ( &fun )
23 , m_dim ( fun.dimension() )
24 , m_arg ( fun.dimension() , 0 )
25 {}
26
27 AdapterIFunction:: AdapterIFunction ( const AdapterIFunction& right )
28 : AbsFunction ( )
29 , m_fun ( right.m_fun )
30 , m_dim ( right.m_dim )
31 , m_arg ( right.m_arg )
32 {}
33
34 AdapterIFunction::~AdapterIFunction() = default;
35
36 double AdapterIFunction::operator() ( double x ) const
37 {
38 for ( size_t i = 0; i < m_dim; ++i ) { m_arg[i] = 0.0 ; }
39 m_arg[0] = x ;
40 return m_fun -> value ( m_arg ) ;
41 }
42
43 double AdapterIFunction::operator() ( const Genfun::Argument& x ) const
44 {
45 for ( size_t i = 0; i < m_dim; ++i ) { m_arg[i] = x[i] ; }
46 return m_fun -> value ( m_arg ) ;
47 }
48
49 Genfun::Derivative AdapterIFunction::partial( unsigned int i ) const
50 {
51 if ( i >= m_dim )
52 {
53 const AbsFunction& aux = GaudiMath::Constant( 0 , m_dim ) ;
54 return Genfun::FunctionNoop( &aux ) ;
55 };
56 const AbsFunction& aux = GaudiMath::Derivative( *this , i ) ;
57 return Genfun::FunctionNoop ( &aux ) ;
58 }
59
60 FUNCTION_OBJECT_IMP( Adapter2DoubleFunction )
61
62 Adapter2DoubleFunction::Adapter2DoubleFunction
63 ( Adapter2DoubleFunction::Function func )
64 : AbsFunction ( )
65 , m_func ( func )
66 {}
67
68 Adapter2DoubleFunction:: Adapter2DoubleFunction
69 ( const Adapter2DoubleFunction& right )
70 : AbsFunction ( )
71 , m_func ( right.m_func )
72 {}
73
74 Adapter2DoubleFunction::~Adapter2DoubleFunction() = default;
75
76 double Adapter2DoubleFunction::operator()
77 ( double x ) const
78 { return m_func ( x , 0 ) ; }
79
80 double Adapter2DoubleFunction::operator()
81 ( const Genfun::Argument& x ) const
82 { return m_func ( x[0] , x[1] ) ; }
83
84 double Adapter2DoubleFunction::operator()
85 ( const double x ,
86 const double y ) const
87 { return m_func ( x , y ) ; }
88
90 Genfun::Derivative Adapter2DoubleFunction::partial( unsigned int i ) const
91 {
92 if ( i >= 2 )
93 {
94 const AbsFunction& aux = GaudiMath::Constant( 0 , 2 ) ;
95 return Genfun::FunctionNoop( &aux ) ;
96 };
97 const AbsFunction& aux = GaudiMath::Derivative( *this , i ) ;
98 return Genfun::FunctionNoop ( &aux ) ;
99 }
100
101 FUNCTION_OBJECT_IMP( Adapter3DoubleFunction )
102
103 Adapter3DoubleFunction::Adapter3DoubleFunction
104 ( Adapter3DoubleFunction::Function func )
105 : AbsFunction ( )
106 , m_func ( func )
107 {}
108
109 Adapter3DoubleFunction:: Adapter3DoubleFunction
110 ( const Adapter3DoubleFunction& right )
111 : AbsFunction ( )
112 , m_func ( right.m_func )
113 {}
114
115 Adapter3DoubleFunction::~Adapter3DoubleFunction() = default;
116
117 double Adapter3DoubleFunction::operator()
118 ( double x ) const
119 { return m_func ( x , 0 , 0 ) ; }
120
121 double Adapter3DoubleFunction::operator()
122 ( const Genfun::Argument& x ) const
123 { return m_func ( x[0] , x[1] , x[2] ) ; }
124
125 double Adapter3DoubleFunction::operator()
126 ( const double x ,
127 const double y ,
128 const double z ) const
129 { return m_func ( x , y , z ) ; }
130
132 Genfun::Derivative Adapter3DoubleFunction::partial( unsigned int i ) const
133 {
134 if ( i >= 3 )
135 {
136 const AbsFunction& aux = GaudiMath::Constant( 0 , 3 ) ;
137 return Genfun::FunctionNoop( &aux ) ;
138 };
139 const AbsFunction& aux = GaudiMath::Derivative( *this , i ) ;
140 return Genfun::FunctionNoop ( &aux ) ;
141 }
142
143 // ========================================================================
145 // ========================================================================
146 FUNCTION_OBJECT_IMP( SimpleFunction )
147 // ========================================================================
148
149 // =======================================================================
153 // ========================================================================
154 SimpleFunction::SimpleFunction
155 ( SimpleFunction::Function1 func )
156 : AbsFunction ()
157 , m_case ( SimpleFunction::TrivialArg )
158 , m_DIM ( 1 )
159 , m_func1 ( func )
160 , m_func2 ( nullptr )
161 , m_func3 ( nullptr )
162 {}
163 // ========================================================================
164
165 // ========================================================================
170 // ========================================================================
171 SimpleFunction::SimpleFunction
172 ( SimpleFunction::Function2 func ,
173 const size_t dim )
174 : AbsFunction ()
175 , m_case ( SimpleFunction::ArrayArg )
176 , m_DIM ( dim )
177 , m_func1 ( nullptr )
178 , m_func2 ( func )
179 , m_arg2 ( new double[dim] )
180 , m_func3 ( nullptr )
181 {
182 }
183 // ========================================================================
184
185 // ========================================================================
190 // ========================================================================
191 SimpleFunction::SimpleFunction
192 ( SimpleFunction::Function3 func ,
193 const size_t dim )
194 : AbsFunction ()
195 , m_case ( SimpleFunction::VectorArg )
196 , m_DIM ( dim )
197 , m_func1 ( nullptr )
198 , m_func2 ( nullptr )
199 , m_func3 ( func )
200 , m_arg3 ( dim , 0 )
201 {}
202 // ========================================================================
203
204 // ========================================================================
206 // ========================================================================
207 SimpleFunction::SimpleFunction
208 ( const SimpleFunction& right )
209 : AbsFunction ()
210 , m_case ( right.m_case )
211 , m_DIM ( right.m_DIM )
212 , m_func1 ( right.m_func1 )
213 , m_func2 ( right.m_func2 )
214 , m_func3 ( right.m_func3 )
215 , m_arg3 ( right.m_arg3 )
216 {
217 if ( right.m_arg2 )
218 {
219 m_arg2.reset( new double[m_DIM] );
220 std::copy_n(right.m_arg2.get(), m_DIM, m_arg2.get());
221 }
222 }
223 // ========================================================================
224
225 // ========================================================================
226
227 // ========================================================================
229 // ========================================================================
230 Genfun::Derivative SimpleFunction::partial( unsigned int i ) const
231 {
232 if ( i >= m_DIM )
233 {
234 const AbsFunction& aux = GaudiMath::Constant( 0 , m_DIM ) ;
235 return Genfun::FunctionNoop( &aux ) ;
236 }
237 const AbsFunction& aux = GaudiMath::Derivative( *this , i ) ;
238 return Genfun::FunctionNoop( &aux );
239 }
240
241 // ========================================================================
243 // ========================================================================
244 double SimpleFunction::operator() ( double value ) const
245 {
246 double result = 0 ;
247 switch ( m_case )
248 {
249 case TrivialArg :
250 result = (*m_func1) ( value ) ; break ;
251 case ArrayArg :
252 std::fill_n( m_arg2.get() , m_DIM , 0.0 );
253 m_arg2[0] = value ;
254 result = (*m_func2) ( m_arg2.get() ) ; break ;
255 case VectorArg :
256 std::fill ( m_arg3.begin () , m_arg3.end () , 0.0 );
257 m_arg3[0] = value ;
258 result = (*m_func3) ( m_arg3 ) ; break ;
259 default:
260 break ;
261 };
262 return result ;
263 }
264 // ========================================================================
265
266 // ========================================================================
268 // ========================================================================
269 double SimpleFunction::operator() ( const Argument& argument ) const
270 {
271 double result = 0 ;
272 switch ( m_case )
273 {
274 case TrivialArg :
275 result = (*m_func1) ( argument[0] ) ; break ;
276 case ArrayArg :
277 for( size_t i = 0 ; i < m_DIM ; ++i ) { m_arg2[i] = argument[i] ; }
278 return (*m_func2)( m_arg2.get() ) ; ; break ;
279 case VectorArg :
280 for( size_t i = 0 ; i < m_DIM ; ++i ) { m_arg3[i] = argument[i] ; }
281 result = (*m_func3) ( m_arg3 ) ; break ;
282 default:
283 break ;
284 }
285 return result ;
286 }
287
288 } // end of namespace GaudiMathImplementation
289 } // end of namespace Genfun
290
291
292 // ============================================================================
293 // The END
294 // ============================================================================
Genfun::GaudiMathImplementation::SimpleFunction::partial
virtual Genfun::Derivative partial(unsigned int i) const
Derivatives.
Definition: Adapter.cpp:230
Genfun::GaudiMathImplementation::AdapterIFunction::operator()
virtual double operator()(double a) const
Definition: Adapter.cpp:36
Genfun::GaudiMathImplementation::Adapter2DoubleFunction::~Adapter2DoubleFunction
virtual ~Adapter2DoubleFunction()
virtual destructor
Genfun::GaudiMathImplementation::SimpleFunction::SimpleFunction
SimpleFunction()
Genfun::GaudiMathImplementation::SimpleFunction::m_func3
Function3 m_func3
Definition: FunAdapters.h:270
Genfun::GaudiMathImplementation::SimpleFunction::m_arg2
std::unique_ptr< double[]> m_arg2
Definition: FunAdapters.h:268
Genfun::GaudiMathImplementation::SimpleFunction
Definition: FunAdapters.h:202
Genfun::GaudiMathImplementation::Adapter2DoubleFunction::partial
virtual Genfun::Derivative partial(unsigned int i) const
Derivatives.
Definition: Adapter.cpp:90
Genfun::GaudiMathImplementation::AdapterIFunction::partial
virtual Genfun::Derivative partial(unsigned int i) const
Derivatives.
Definition: Adapter.cpp:49
std::vector::end
T end(T...args)
GaudiMath::Function
Genfun::AbsFunction Function
Definition: GaudiMath.h:24
std::copy_n
T copy_n(T...args)
GaudiMath::Derivative
Genfun::GaudiMathImplementation::NumericalDerivative Derivative
Definition: GaudiMath.h:29
Genfun::GaudiMathImplementation::Adapter3DoubleFunction::partial
virtual Genfun::Derivative partial(unsigned int i) const
Derivatives.
Definition: Adapter.cpp:132
Genfun::GaudiMathImplementation::AdapterIFunction::m_dim
size_t m_dim
Definition: FunAdapters.h:62
AIDA
GaudiKernel.
Definition: Fill.h:8
Genfun::GaudiMathImplementation::SimpleFunction::m_func2
Function2 m_func2
Definition: FunAdapters.h:267
Genfun::GaudiMathImplementation::AdapterIFunction::AdapterIFunction
AdapterIFunction()
Genfun::GaudiMathImplementation::Adapter2DoubleFunction::Adapter2DoubleFunction
Adapter2DoubleFunction()
Genfun::GaudiMathImplementation::SimpleFunction::TrivialArg
Definition: FunAdapters.h:209
Genfun::GaudiMathImplementation::Adapter2DoubleFunction
constructor from the trivial function with two argument
Definition: FunAdapters.h:91
Genfun::GaudiMathImplementation::SimpleFunction::m_arg3
std::vector< double > m_arg3
Definition: FunAdapters.h:271
Genfun::GaudiMathImplementation::Adapter2DoubleFunction::m_func
Function m_func
Definition: FunAdapters.h:125
Genfun::GaudiMathImplementation::SimpleFunction::operator()
virtual double operator()(double) const
Function value.
Definition: Adapter.cpp:244
Genfun::GaudiMathImplementation::SimpleFunction::VectorArg
Definition: FunAdapters.h:209
Genfun::GaudiMathImplementation::Adapter3DoubleFunction::~Adapter3DoubleFunction
virtual ~Adapter3DoubleFunction()
virtual destructor
GaudiPluginService.cpluginsvc.func
tuple func
Definition: cpluginsvc.py:218
Genfun::GaudiMathImplementation::Adapter3DoubleFunction::m_func
Function m_func
Definition: FunAdapters.h:191
dump_component_properties.value
list value
Definition: dump_component_properties.py:12
Genfun::GaudiMathImplementation::SimpleFunction::ArrayArg
Definition: FunAdapters.h:209
Genfun::GaudiMathImplementation::SimpleFunction::m_DIM
size_t m_DIM
Definition: FunAdapters.h:263
Genfun::GaudiMathImplementation::Adapter3DoubleFunction
constructor from the trivial function with two argument
Definition: FunAdapters.h:154
std::unique_ptr::get
T get(T...args)
Genfun::GaudiMathImplementation::AdapterIFunction::m_fun
const AIDA::IFunction * m_fun
Definition: FunAdapters.h:61
Genfun::GaudiMathImplementation::AdapterIFunction::~AdapterIFunction
virtual ~AdapterIFunction()
desctructor
Genfun::GaudiMathImplementation::SimpleFunction::m_case
Case m_case
Definition: FunAdapters.h:262
std::vector::begin
T begin(T...args)
Genfun::GaudiMathImplementation::AdapterIFunction::m_arg
std::vector< double > m_arg
Definition: FunAdapters.h:63
fun
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26
Genfun::GaudiMathImplementation::SimpleFunction::Function2
double(* Function2)(const double *)
Definition: FunAdapters.h:206
std::fill_n
T fill_n(T...args)
Genfun::GaudiMathImplementation::SimpleFunction::Function3
double(* Function3)(const std::vector< double > &)
Definition: FunAdapters.h:207
Genfun::GaudiMathImplementation::SimpleFunction::m_func1
Function1 m_func1
Definition: FunAdapters.h:265
Genfun
CLHEP.
Definition: IEqSolver.h:13
std::fill
T fill(T...args)
ana.i
list i
Definition: ana.py:128
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:31