6 #include "GaudiKernel/GaudiException.h"
10 #include "GaudiMath/NumericalDerivative.h"
11 #include "GaudiMath/Constant.h"
15 #include "gsl/gsl_errno.h"
16 #include "gsl/gsl_diff.h"
17 #include "gsl/gsl_math.h"
35 namespace GaudiMathImplementation
40 FUNCTION_OBJECT_IMP( NumericalDerivative )
51 NumericalDerivative::NumericalDerivative
52 ( const AbsFunction& function ,
56 , m_function ( function.clone() )
58 , m_DIM ( function.dimensionality() )
60 , m_argument ( function.dimensionality() )
61 , m_result ( GSL_NEGINF )
62 , m_error ( GSL_POSINF )
64 if( m_index >= m_DIM )
65 { Exception (
"::constructor invalid variable index " ) ; };
77 , m_DIM ( right.
m_DIM )
79 , m_argument ( right.
m_DIM )
80 , m_result ( GSL_NEGINF )
81 , m_error ( GSL_POSINF )
99 {
Exception (
"::partial(i): invalid variable index" ) ; }
100 const AbsFunction& aux =
102 return FunctionNoop( &aux ) ;
109 double NumericalDerivative::operator()
110 (
const Argument& argument )
const
113 m_result = GSL_NEGINF ;
114 m_error = GSL_POSINF ;
117 if( argument.dimension() != m_DIM )
118 { Exception (
"::operator():invalid argument size" ) ; };
121 {
for(
size_t i = 0 ;
i < m_DIM ; ++
i ){ m_argument[
i] = argument[
i];}}
124 GSL_Helper helper( *m_function , m_argument , m_index );
131 double x = argument[m_index];
136 ierrno = gsl_diff_central ( &F , x , &m_result , &m_error ) ; break ;
138 ierrno = gsl_diff_forward ( &F , x , &m_result , &m_error ) ; break ;
140 ierrno = gsl_diff_backward ( &F , x , &m_result , &m_error ) ; break ;
142 Exception (
"::operator(): invalid diffrentiation type " ) ;
146 { gsl_error (
" NumericalDerivative:: the error from gsl_diff_XXXX" ,
147 __FILE__ , __LINE__ , ierrno ) ; }
163 if( 1 !=
m_DIM ) {
Exception (
"operator(): invalid argument size " ); }
167 return (*
this)( arg ) ;
175 (
const std::string& message ,
179 "*GaudiMath*" , sc ) ;
std::unique_ptr< const AbsFunction > m_function
Define general base for Gaudi exception.
const Type & type() const
type
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)
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 ...