BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering

Description

GradFunctor class for Multidimensional gradient functions. It is used to wrap in a very C++ callable object to make gradient functions. It can be constructed in three different way:

  1. from an object implementing both double operator()( const double * ) for the function evaluation and double Derivative(const double *, int icoord) for the partial derivatives
  2. from an object implementing any member function like Foo::XXX(const double *) for the function evaluation and any member function like Foo::XXX(const double *, int icoord) for the partial derivatives
  3. from an function object implementing double operator()( const double * ) for the function evaluation and another function object implementing double operator() (const double *, int icoord) for the partial derivatives

The function dimension is required when constructing the functor.

Definition at line 577 of file Functor.h.

Inheritance diagram for ROOT::Math::GradFunctor:
[legend]
Collaboration diagram for ROOT::Math::GradFunctor:
[legend]

Public Types

typedef T BackendType
 
typedef IBaseFunctionMultiDimTempl< T > BaseFunc
 
typedef IGradientMultiDimTempl< T > BaseGrad
 
typedef FunctorImpl< IGradientFunctionMultiDimImpl
 
typedef IGradientFunctionMultiDim::BaseFunc ImplBase
 

Public Member Functions

 GradFunctor ()
 
template<typename Func , typename GradFunc >
 GradFunctor (const Func &f, const GradFunc &g, int dim)
 
template<typename Func >
 GradFunctor (const Func &f, unsigned int dim)
 
 GradFunctor (const GradFunctor &rhs)
 
template<class PtrObj , typename MemFn , typename GradMemFn >
 GradFunctor (const PtrObj &p, MemFn memFn, GradMemFn gradFn, unsigned int dim)
 
virtual ~GradFunctor ()
 
ImplBaseClone () const
 
Derivative (const T *x, unsigned int icoord=0) const
 
virtual void FdF (const T *x, T &f, T *df) const
 
virtual void Gradient (const T *x, T *grad) const
 
unsigned int NDim () const
 
virtual unsigned int NDim () const=0
 
operator() (const T *x) const
 
GradFunctoroperator= (const GradFunctor &rhs)
 

Private Member Functions

double DoDerivative (const double *x, unsigned int icoord) const
 
double DoEval (const double *x) const
 

Private Attributes

std::unique_ptr< ImplfImpl
 

Member Typedef Documentation

◆ BackendType

template<class T >
typedef T ROOT::Math::IBaseFunctionMultiDimTempl< T >::BackendType
inherited

Definition at line 66 of file IFunction.h.

◆ BaseFunc

Definition at line 330 of file IFunction.h.

◆ BaseGrad

template<class T >
typedef IGradientMultiDimTempl<T> ROOT::Math::IGradientFunctionMultiDimTempl< T >::BaseGrad
inherited

Definition at line 331 of file IFunction.h.

◆ Impl

◆ ImplBase

Constructor & Destructor Documentation

◆ GradFunctor() [1/5]

ROOT::Math::GradFunctor::GradFunctor ( )
inline

Default constructor

Definition at line 589 of file Functor.h.

589 {}

Referenced by Clone().

◆ GradFunctor() [2/5]

template<typename Func >
ROOT::Math::GradFunctor::GradFunctor ( const Func &  f,
unsigned int  dim 
)
inline

construct from a callable object of multi-dimension implementing operator()(const double *x) and Derivative(const double * x,icoord)

Definition at line 597 of file Functor.h.

597  :
598  fImpl(new FunctorHandler<GradFunctor,Func>(dim,f) )
599  {}
std::unique_ptr< Impl > fImpl
Definition: Functor.h:664

◆ GradFunctor() [3/5]

template<class PtrObj , typename MemFn , typename GradMemFn >
ROOT::Math::GradFunctor::GradFunctor ( const PtrObj &  p,
MemFn  memFn,
GradMemFn  gradFn,
unsigned int  dim 
)
inline

construct from a pointer to member function and member function types for function and derivative evaluations

Definition at line 605 of file Functor.h.

606  : fImpl(new MemGradFunHandler<GradFunctor, PtrObj, MemFn, GradMemFn>(dim, p, memFn, gradFn))
607  {}

◆ GradFunctor() [4/5]

template<typename Func , typename GradFunc >
ROOT::Math::GradFunctor::GradFunctor ( const Func &  f,
const GradFunc &  g,
int  dim 
)
inline

construct for Gradient Functions of multi-dimension Func gives the function evaluatiion, GradFunc the partial derivatives The function dimension is required

Definition at line 615 of file Functor.h.

615  :
616  fImpl(new FunctorGradHandler<GradFunctor,Func,GradFunc>(dim, f, g) )
617  { }

◆ ~GradFunctor()

virtual ROOT::Math::GradFunctor::~GradFunctor ( )
inlinevirtual

Destructor (no operations)

Definition at line 623 of file Functor.h.

623 {}

◆ GradFunctor() [5/5]

ROOT::Math::GradFunctor::GradFunctor ( const GradFunctor rhs)
inline

Copy constructor for functor based on ROOT::Math::IMultiGradFunction

Definition at line 629 of file Functor.h.

629  :
630  ImplBase()
631  {
632  if (rhs.fImpl)
633  fImpl = std::unique_ptr<Impl>(rhs.fImpl->Copy());
634  }
IGradientFunctionMultiDim::BaseFunc ImplBase
Definition: Functor.h:583

References fImpl.

Member Function Documentation

◆ Clone()

ImplBase* ROOT::Math::GradFunctor::Clone ( ) const
inlinevirtual

Clone a function. Each derived class must implement their version of the Clone method

Implements ROOT::Math::IBaseFunctionMultiDimTempl< T >.

Definition at line 647 of file Functor.h.

647 { return new GradFunctor(*this); }

References GradFunctor().

Here is the call graph for this function:

◆ Derivative()

template<class T >
T ROOT::Math::IGradientMultiDimTempl< T >::Derivative ( const T *  x,
unsigned int  icoord = 0 
) const
inlineinherited

Return the partial derivative with respect to the passed coordinate

Definition at line 217 of file IFunction.h.

217 { return DoDerivative(x, icoord); }
virtual T DoDerivative(const T *x, unsigned int icoord) const =0

References ROOT::Math::IGradientMultiDimTempl< T >::DoDerivative().

Referenced by ROOT::Math::MinimTransformFunction::DoDerivative(), and ROOT::Math::IGradientFunctionMultiDimTempl< T >::Gradient().

Here is the call graph for this function:

◆ DoDerivative()

double ROOT::Math::GradFunctor::DoDerivative ( const double *  x,
unsigned int  icoord 
) const
inlineprivate

Definition at line 660 of file Functor.h.

660  {
661  return fImpl->Derivative(x,icoord);
662  }

References fImpl.

◆ DoEval()

double ROOT::Math::GradFunctor::DoEval ( const double *  x) const
inlineprivate

Definition at line 655 of file Functor.h.

655  {
656  return (*fImpl)(x);
657  }

References fImpl.

◆ FdF()

template<class T >
virtual void ROOT::Math::IGradientFunctionMultiDimTempl< T >::FdF ( const T *  x,
T &  f,
T *  df 
) const
inlinevirtualinherited

Optimized method to evaluate at the same time the function value and derivative at a point x. Often both value and derivatives are needed and it is often more efficient to compute them at the same time. Derived class should implement this method if performances play an important role and if it is faster to evaluate value and derivative at the same time

Implements ROOT::Math::IGradientMultiDimTempl< T >.

Definition at line 357 of file IFunction.h.

358  {
359  f = BaseFunc::operator()(x);
360  Gradient(x, df);
361  }
virtual void Gradient(const T *x, T *grad) const
Definition: IFunction.h:342

References ROOT::Math::IGradientFunctionMultiDimTempl< T >::Gradient(), and ROOT::Math::IBaseFunctionMultiDimTempl< T >::operator()().

Here is the call graph for this function:

◆ Gradient()

template<class T >
virtual void ROOT::Math::IGradientFunctionMultiDimTempl< T >::Gradient ( const T *  x,
T *  grad 
) const
inlinevirtualinherited

Evaluate all the vector of function derivatives (gradient) at a point x. Derived classes must re-implement it if more efficient than evaluting one at a time

Implements ROOT::Math::IGradientMultiDimTempl< T >.

Definition at line 342 of file IFunction.h.

343  {
344  unsigned int ndim = NDim();
345  for (unsigned int icoord = 0; icoord < ndim; ++icoord)
346  grad[icoord] = BaseGrad::Derivative(x, icoord);
347  }
virtual unsigned int NDim() const=0
T Derivative(const T *x, unsigned int icoord=0) const
Definition: IFunction.h:217

References ROOT::Math::IGradientMultiDimTempl< T >::Derivative(), and ROOT::Math::IGradientFunctionMultiDimTempl< T >::NDim().

Referenced by ROOT::Math::IGradientFunctionMultiDimTempl< T >::FdF().

Here is the call graph for this function:

◆ NDim() [1/2]

unsigned int ROOT::Math::GradFunctor::NDim ( ) const
inlinevirtual

Retrieve the dimension of the function

Implements ROOT::Math::IBaseFunctionMultiDimTempl< T >.

Definition at line 650 of file Functor.h.

650 { return fImpl->NDim(); }

References fImpl.

◆ NDim() [2/2]

template<class T >
virtual unsigned int ROOT::Math::IBaseFunctionMultiDimTempl< T >::NDim
inherited

◆ operator()()

template<class T >
T ROOT::Math::IBaseFunctionMultiDimTempl< T >::operator() ( const T *  x) const
inlineinherited

Evaluate the function at a point x[]. Use the pure virtual private method DoEval which must be implemented by the sub-classes

Definition at line 92 of file IFunction.h.

93  {
94  return DoEval(x);
95  }
virtual T DoEval(const T *x) const =0

References ROOT::Math::IBaseFunctionMultiDimTempl< T >::DoEval().

Referenced by ROOT::Math::IGradientFunctionMultiDimTempl< T >::FdF().

Here is the call graph for this function:

◆ operator=()

GradFunctor& ROOT::Math::GradFunctor::operator= ( const GradFunctor rhs)
inline

Assignment operator

Definition at line 639 of file Functor.h.

639  {
640  GradFunctor copy(rhs);
641  fImpl.swap(copy.fImpl);
642  return *this;
643  }

References fImpl.

Member Data Documentation

◆ fImpl

std::unique_ptr<Impl> ROOT::Math::GradFunctor::fImpl
private

Definition at line 664 of file Functor.h.

Referenced by GradFunctor(), DoDerivative(), DoEval(), NDim(), and operator=().


The documentation for this class was generated from the following file: