00001
00002
00003
00004
00005
00006 #include "GaudiMath/GaudiMath.h"
00007
00008
00009
00010 #include "AIDA/IFunction.h"
00011
00012 #include <cstring>
00013
00014 namespace Genfun
00015 {
00016 namespace GaudiMathImplementation
00017 {
00018
00019 FUNCTION_OBJECT_IMP( AdapterIFunction )
00020
00021 AdapterIFunction::AdapterIFunction ( const AIDA::IFunction& fun)
00022 : AbsFunction ( )
00023 , m_fun ( &fun )
00024 , m_dim ( fun.dimension() )
00025 , m_arg ( fun.dimension() , 0 )
00026 {}
00027
00028 AdapterIFunction:: AdapterIFunction ( const AdapterIFunction& right )
00029 : AbsFunction ( )
00030 , m_fun ( right.m_fun )
00031 , m_dim ( right.m_dim )
00032 , m_arg ( right.m_arg )
00033 {}
00034
00035 AdapterIFunction::~AdapterIFunction(){}
00036
00037 double AdapterIFunction::operator() ( double x ) const
00038 {
00039 for ( size_t i = 0; i < m_dim; ++i ) { m_arg[i] = 0.0 ; }
00040 m_arg[0] = x ;
00041 return m_fun -> value ( m_arg ) ;
00042 }
00043
00044 double AdapterIFunction::operator() ( const Genfun::Argument& x ) const
00045 {
00046 for ( size_t i = 0; i < m_dim; ++i ) { m_arg[i] = x[i] ; }
00047 return m_fun -> value ( m_arg ) ;
00048 }
00049
00050 Genfun::Derivative AdapterIFunction::partial( unsigned int i ) const
00051 {
00052 if ( i >= m_dim )
00053 {
00054 const AbsFunction& aux = GaudiMath::Constant( 0 , m_dim ) ;
00055 return Genfun::FunctionNoop( &aux ) ;
00056 };
00057 const AbsFunction& aux = GaudiMath::Derivative( *this , i ) ;
00058 return Genfun::FunctionNoop ( &aux ) ;
00059 }
00060
00061 FUNCTION_OBJECT_IMP( Adapter2DoubleFunction )
00062
00063 Adapter2DoubleFunction::Adapter2DoubleFunction
00064 ( Adapter2DoubleFunction::Function func )
00065 : AbsFunction ( )
00066 , m_func ( func )
00067 {}
00068
00069 Adapter2DoubleFunction:: Adapter2DoubleFunction
00070 ( const Adapter2DoubleFunction& right )
00071 : AbsFunction ( )
00072 , m_func ( right.m_func )
00073 {}
00074
00075 Adapter2DoubleFunction::~Adapter2DoubleFunction(){}
00076
00077 double Adapter2DoubleFunction::operator()
00078 ( double x ) const
00079 { return m_func ( x , 0 ) ; }
00080
00081 double Adapter2DoubleFunction::operator()
00082 ( const Genfun::Argument& x ) const
00083 { return m_func ( x[0] , x[1] ) ; }
00084
00085 double Adapter2DoubleFunction::operator()
00086 ( const double x ,
00087 const double y ) const
00088 { return m_func ( x , y ) ; }
00089
00091 Genfun::Derivative Adapter2DoubleFunction::partial( unsigned int i ) const
00092 {
00093 if ( i >= 2 )
00094 {
00095 const AbsFunction& aux = GaudiMath::Constant( 0 , 2 ) ;
00096 return Genfun::FunctionNoop( &aux ) ;
00097 };
00098 const AbsFunction& aux = GaudiMath::Derivative( *this , i ) ;
00099 return Genfun::FunctionNoop ( &aux ) ;
00100 }
00101
00102 FUNCTION_OBJECT_IMP( Adapter3DoubleFunction )
00103
00104 Adapter3DoubleFunction::Adapter3DoubleFunction
00105 ( Adapter3DoubleFunction::Function func )
00106 : AbsFunction ( )
00107 , m_func ( func )
00108 {}
00109
00110 Adapter3DoubleFunction:: Adapter3DoubleFunction
00111 ( const Adapter3DoubleFunction& right )
00112 : AbsFunction ( )
00113 , m_func ( right.m_func )
00114 {}
00115
00116 Adapter3DoubleFunction::~Adapter3DoubleFunction(){}
00117
00118 double Adapter3DoubleFunction::operator()
00119 ( double x ) const
00120 { return m_func ( x , 0 , 0 ) ; }
00121
00122 double Adapter3DoubleFunction::operator()
00123 ( const Genfun::Argument& x ) const
00124 { return m_func ( x[0] , x[1] , x[2] ) ; }
00125
00126 double Adapter3DoubleFunction::operator()
00127 ( const double x ,
00128 const double y ,
00129 const double z ) const
00130 { return m_func ( x , y , z ) ; }
00131
00133 Genfun::Derivative Adapter3DoubleFunction::partial( unsigned int i ) const
00134 {
00135 if ( i >= 3 )
00136 {
00137 const AbsFunction& aux = GaudiMath::Constant( 0 , 3 ) ;
00138 return Genfun::FunctionNoop( &aux ) ;
00139 };
00140 const AbsFunction& aux = GaudiMath::Derivative( *this , i ) ;
00141 return Genfun::FunctionNoop ( &aux ) ;
00142 }
00143
00144
00146
00147 FUNCTION_OBJECT_IMP( SimpleFunction )
00148
00149
00150
00154
00155 SimpleFunction::SimpleFunction
00156 ( SimpleFunction::Function1 func )
00157 : AbsFunction ()
00158 , m_case ( SimpleFunction::TrivialArg )
00159 , m_DIM ( 1 )
00160 , m_func1 ( func )
00161 , m_func2 ( 0 )
00162 , m_arg2 ( 0 )
00163 , m_func3 ( 0 )
00164 , m_arg3 ( )
00165 {}
00166
00167
00168
00173
00174 SimpleFunction::SimpleFunction
00175 ( SimpleFunction::Function2 func ,
00176 const size_t dim )
00177 : AbsFunction ()
00178 , m_case ( SimpleFunction::ArrayArg )
00179 , m_DIM ( dim )
00180 , m_func1 ( 0 )
00181 , m_func2 ( func )
00182 , m_arg2 ( 0 )
00183 , m_func3 ( 0 )
00184 , m_arg3 ( )
00185 {
00186 m_arg2 = new double[dim];
00187 }
00188
00189
00190
00195
00196 SimpleFunction::SimpleFunction
00197 ( SimpleFunction::Function3 func ,
00198 const size_t dim )
00199 : AbsFunction ()
00200 , m_case ( SimpleFunction::VectorArg )
00201 , m_DIM ( dim )
00202 , m_func1 ( 0 )
00203 , m_func2 ( 0 )
00204 , m_arg2 ( 0 )
00205 , m_func3 ( func )
00206 , m_arg3 ( dim , 0 )
00207 {}
00208
00209
00210
00212
00213 SimpleFunction::SimpleFunction
00214 ( const SimpleFunction& right )
00215 : AbsFunction ()
00216 , m_case ( right.m_case )
00217 , m_DIM ( right.m_DIM )
00218 , m_func1 ( right.m_func1 )
00219 , m_func2 ( right.m_func2 )
00220 , m_arg2 ( 0 )
00221 , m_func3 ( right.m_func3 )
00222 , m_arg3 ( right.m_arg3 )
00223 {
00224 if ( 0 != right.m_arg2 )
00225 {
00226 std::memcpy(m_arg2, right.m_arg2, m_DIM);
00227 }
00228 }
00229
00230
00231
00233
00234 SimpleFunction::~SimpleFunction()
00235 { if( 0 != m_arg2 ) { delete m_arg2 ; m_arg2 = 0 ;} }
00236
00237
00238
00240
00241 Genfun::Derivative SimpleFunction::partial( unsigned int i ) const
00242 {
00243 if ( i >= m_DIM )
00244 {
00245 const AbsFunction& aux = GaudiMath::Constant( 0 , m_DIM ) ;
00246 return Genfun::FunctionNoop( &aux ) ;
00247 }
00248 const AbsFunction& aux = GaudiMath::Derivative( *this , i ) ;
00249 return Genfun::FunctionNoop( &aux );
00250 }
00251
00252
00254
00255 double SimpleFunction::operator() ( double value ) const
00256 {
00257 double result = 0 ;
00258 switch ( m_case )
00259 {
00260 case TrivialArg :
00261 result = (*m_func1) ( value ) ; break ;
00262 case ArrayArg :
00263 std::fill ( m_arg2 , m_arg2 + m_DIM , 0.0 );
00264 m_arg2[0] = value ;
00265 result = (*m_func2) ( m_arg2 ) ; break ;
00266 case VectorArg :
00267 std::fill ( m_arg3.begin () , m_arg3.end () , 0.0 );
00268 m_arg3[0] = value ;
00269 result = (*m_func3) ( m_arg3 ) ; break ;
00270 default:
00271 break ;
00272 };
00273 return result ;
00274 }
00275
00276
00277
00279
00280 double SimpleFunction::operator() ( const Argument& argument ) const
00281 {
00282 double result = 0 ;
00283 switch ( m_case )
00284 {
00285 case TrivialArg :
00286 result = (*m_func1) ( argument[0] ) ; break ;
00287 case ArrayArg :
00288 for( size_t i = 0 ; i < m_DIM ; ++i ) { m_arg2[i] = argument[i] ; }
00289 return (*m_func2)( m_arg2 ) ; ; break ;
00290 case VectorArg :
00291 for( size_t i = 0 ; i < m_DIM ; ++i ) { m_arg3[i] = argument[i] ; }
00292 result = (*m_func3) ( m_arg3 ) ; break ;
00293 default:
00294 break ;
00295 }
00296 return result ;
00297 }
00298
00299 }
00300 }
00301
00302
00303
00304
00305