GSLFunAdapters.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ============================================================================
4 // GaudiGSL/GaudiMath
5 // ============================================================================
7 #include "GaudiMath/GaudiMath.h"
8 // ============================================================================
9 // GSL
10 // ============================================================================
11 #include "gsl/gsl_mode.h"
12 #include "gsl/gsl_sf_result.h"
13 // ============================================================================
14 
22 namespace Genfun
23 {
24  namespace GaudiMathImplementation
25  {
26 
29  : AbsFunction()
30  , m_function ( function )
31  , m_result ( new gsl_sf_result() )
32  {
33  m_result -> val = -1.e+10 ;
34  m_result -> err = -1.e+10 ;
35  }
36 
39  : AbsFunction()
40  , m_function ( func.m_function )
41  , m_result ( new gsl_sf_result() )
42  {
43  m_result -> val = func.m_result -> val ;
44  m_result -> err = func.m_result -> err ;
45  }
46 
47  double GSLFunctionWithError::operator()
48  ( double x ) const
49  {
50  (*m_function)( x , m_result.get() ) ;
51  return m_result -> val ;
52  }
53 
54  double GSLFunctionWithError::operator()
55  ( const Genfun::Argument& x ) const
56  {
57  (*m_function)( x[0] , m_result.get() ) ;
58  return m_result -> val ;
59  }
60 
62  ( unsigned int i ) const
63  {
64  if( i >= 1 )
65  {
66  const AbsFunction& aux = GaudiMath::Constant( 0 , 1 ) ;
67  return Genfun::FunctionNoop( &aux ) ;
68  };
69  const AbsFunction& aux = GaudiMath::Derivative( *this , i) ;
70  return Genfun::FunctionNoop( &aux ) ;
71  }
72 
74  { return m_function ; }
75 
76  const gsl_sf_result& GSLFunctionWithError::result () const
77  { return *m_result ; }
78 
79  double GSLFunctionWithError::error () const
80  { return m_result -> err ; }
81 
82 
85  const gsl_mode_t& mod )
86  : AbsFunction()
87  , m_function ( function )
88  , m_mode ( new gsl_mode_t() )
89  {
90  *m_mode = mod ;
91  }
92 
94  ( const GSLFunctionWithMode& func )
95  : AbsFunction()
96  , m_function ( func.m_function )
97  , m_mode ( new gsl_mode_t () )
98  {
99  *m_mode = *(func.m_mode) ;
100  }
101 
102  double GSLFunctionWithMode::operator()
103  ( double x ) const
104  { return (*m_function)( x , *m_mode ) ; }
105 
106  double GSLFunctionWithMode::operator()
107  ( const Genfun::Argument& x ) const
108  { return (*m_function)( x[0] , *m_mode ) ; }
109 
111  ( unsigned int i ) const
112  {
113  if( i >= 1 )
114  {
115  const AbsFunction& aux = GaudiMath::Constant( 0 , 1 ) ;
116  return Genfun::FunctionNoop( &aux ) ;
117  };
118  const AbsFunction& aux = GaudiMath::Derivative( *this , i) ;
119  return Genfun::FunctionNoop( &aux ) ;
120  }
121 
123  { return m_function ; }
124 
125  const gsl_mode_t& GSLFunctionWithMode::mode () const
126  { return *m_mode ; }
127 
128 
131  const gsl_mode_t& mod )
132  : AbsFunction()
133  , m_function ( function )
134  , m_mode ( new gsl_mode_t() )
135  , m_result ( new gsl_sf_result() )
136  {
137  *m_mode = mod ;
138  m_result -> val = -1.e+10 ;
139  m_result -> err = -1.e+10 ;
140  }
141 
144  : AbsFunction()
145  , m_function ( func.m_function )
146  , m_mode ( new gsl_mode_t () )
147  , m_result ( new gsl_sf_result() )
148  {
149  *m_mode = *(func.m_mode) ;
150  m_result -> val = func.m_result -> val ;
151  m_result -> err = func.m_result -> err ;
152  }
153 
154  double GSLFunctionWithModeAndError::operator()
155  ( double x ) const
156  {
157  (*m_function)( x , *m_mode , m_result.get() ) ;
158  return m_result -> val ;
159  }
160 
161  double GSLFunctionWithModeAndError::operator()
162  ( const Genfun::Argument& x ) const
163  {
164  (*m_function)( x[0] , *m_mode , m_result.get() ) ;
165  return m_result -> val ;
166  }
167 
169  ( unsigned int i ) const
170  {
171  if( i >= 1 )
172  {
173  const AbsFunction& aux = GaudiMath::Constant( 0 , 1 ) ;
174  return Genfun::FunctionNoop( &aux ) ;
175  };
176  const AbsFunction& aux = GaudiMath::Derivative( *this , i) ;
177  return Genfun::FunctionNoop( &aux ) ;
178  }
179 
182  { return m_function ; }
183 
184  const gsl_mode_t&
186  { return *m_mode ; }
187 
188  const gsl_sf_result&
190  { return *m_result ; }
191 
192  double
194  { return m_result -> err ; }
195 
196  } // end of namespace GaudiMathImplementation
197 } // end of namespace Genfun
198 
Function function() const
get the function itself
Function function() const
get the function itself
const gsl_sf_result & result() const
get the last evaluated result
double(* Function)(double, gsl_mode_t)
the actual type of the function
const gsl_sf_result & result() const
get the last evaluated result
Genfun::GaudiMathImplementation::NumericalDerivative Derivative
Definition: GaudiMath.h:29
int(* Function)(double, gsl_sf_result *)
the actual type of the function
mandatory macro from CLHEP/GenericFunctions
Genfun::Derivative partial(unsigned int i) const override
Genfun::Derivative partial(unsigned int i) const override
const gsl_mode_t & mode() const
get the current mode
Function function() const
get the function itself
T get(T...args)
Genfun::Derivative partial(unsigned int i) const override
CLHEP.
Definition: IEqSolver.h:13
const gsl_mode_t & mode() const
get the current mode
double error() const
get the error in the last estimate of the result
mandatory macro from CLHEP/GenericFunctions
Genfun::GaudiMathImplementation::Constant Constant
Definition: GaudiMath.h:27
double error() const
get the error in the last estimate of the result
int(* Function)(double, gsl_mode_t, gsl_sf_result *)
the actual type of the function