16 #include "gsl/gsl_errno.h"
17 #include "gsl/gsl_diff.h"
18 #include "gsl/gsl_math.h"
36 namespace GaudiMathImplementation
41 FUNCTION_OBJECT_IMP( NumericalDerivative )
52 NumericalDerivative::NumericalDerivative
53 ( const AbsFunction& function ,
57 , m_function ( function.clone() )
59 , m_DIM ( function.dimensionality() )
61 , m_argument ( function.dimensionality() )
62 , m_result ( GSL_NEGINF )
63 , m_error ( GSL_POSINF )
65 if( m_index >= m_DIM )
66 { Exception (
"::constructor invalid variable index " ) ; };
78 , m_DIM ( right.
m_DIM )
80 , m_argument ( right.
m_DIM )
81 , m_result ( GSL_NEGINF )
82 , m_error ( GSL_POSINF )
107 {
Exception (
"::partial(i): invalid variable index" ) ; }
108 const AbsFunction& aux =
110 return FunctionNoop( &aux ) ;
117 double NumericalDerivative::operator()
118 (
const Argument& argument )
const
121 m_result = GSL_NEGINF ;
122 m_error = GSL_POSINF ;
125 if( argument.dimension() != m_DIM )
126 { Exception (
"::operator():invalid argument size" ) ; };
129 {
for(
size_t i = 0 ;
i < m_DIM ; ++
i ){ m_argument[
i] = argument[
i];}}
132 GSL_Helper helper( *m_function , m_argument , m_index );
139 double x = argument[m_index];
144 ierrno = gsl_diff_central ( &F , x , &m_result , &m_error ) ; break ;
146 ierrno = gsl_diff_forward ( &F , x , &m_result , &m_error ) ; break ;
148 ierrno = gsl_diff_backward ( &F , x , &m_result , &m_error ) ; break ;
150 Exception (
"::operator(): invalid diffrentiation type " ) ;
154 { gsl_error (
" NumericalDerivative:: the error from gsl_diff_XXXX" ,
155 __FILE__ , __LINE__ , ierrno ) ; }
171 if( 1 !=
m_DIM ) {
Exception (
"operator(): invalid argument size " ); }
175 return (*
this)( arg ) ;
183 (
const std::string& message ,
187 "*GaudiMath*" , sc ) ;
Define general base for Gaudi exception.
const Type & type() const
type
virtual ~NumericalDerivative()
virtual destructor
Type
the type of numerical differentiation
virtual double operator()(double argument) const
Function value.
Genfun::GaudiMathImplementation::NumericalDerivative Derivative
const Type & setType(const Type &value)
change the type of the adaptive differentiation
This class is used for returning status codes from appropriate routines.
virtual Derivative partial(unsigned int index) const
Derivatives.
double GSL_Adaptor(double x, void *params)
const AbsFunction * m_function
Numerical derivative (using GSL adaptive numerical differentiation)
StatusCode Exception(const std::string &message, const StatusCode &sc=StatusCode::FAILURE) const
Exception.
the simple structure to be used for adaption interface Genfun::AbsFunction to gsl_function structure ...