Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches

Documentation for class Functor class.

It is used to wrap in a very simple and convenient way multi-dimensional function objects. It can wrap all the following types:

  • any C++ callable object implementation double operator()( const double * )
  • a free C function of type double ()(const double * )
  • an std::function of type std::function<double (double const *)>
  • a member function with the correct signature like Foo::Eval(const double * ). In this case one pass the object pointer and a pointer to the member function (&Foo::Eval)

The function dimension is required when constructing the functor.

Definition at line 49 of file Functor.h.

Public Types

typedef double BackendType
typedef IBaseFunctionMultiDimTempl< doubleBaseFunc

Public Member Functions

 Functor ()
 Default constructor.
template<class PtrObj, typename MemFn>
 Functor (const PtrObj &p, MemFn memFn, unsigned int dim)
 Construct from a pointer to member function (multi-dim type).
 Functor (std::function< double(double const *)> const &f, unsigned int dim)
 Construct from a callable object of multi-dimension with the right signature (implementing double operator()(const double *x)).
FunctorClone () const override
 Clone a function.
double Derivative (const double *x, unsigned int icoord, double *previous_grad, double *previous_g2, double *previous_gstep) const
 In some cases, the derivative algorithm will use information from the previous step, these can be passed in with this overload.
double Derivative (const double *x, unsigned int icoord=0) const
 Return the partial derivative with respect to the passed coordinate.
virtual void FdF (const double *x, double &f, double *df) const
 Optimized method to evaluate at the same time the function value and derivative at a point x.
virtual void Gradient (const double *x, double *grad) const
 Evaluate all the vector of function derivatives (gradient) at a point x.
virtual bool HasGradient () const
unsigned int NDim () const override
 Retrieve the dimension of the function.
double operator() (const double *x) const
 Evaluate the function at a point x[].

Private Member Functions

virtual double DoDerivative (const double *, unsigned int) const
 Function to evaluate the derivative with respect each coordinate. To be implemented by the derived class.
virtual double DoDerivativeWithPrevResult (const double *x, unsigned int icoord, double *, double *, double *) const
 In some cases, the derivative algorithm will use information from the previous step, these can be passed in with this overload.
double DoEval (const double *x) const override
 Implementation of the evaluation function. Must be implemented by derived classes.

Private Attributes

unsigned int fDim
std::function< double(double const *)> fFunc

#include <Math/Functor.h>

Inheritance diagram for ROOT::Math::Functor:
ROOT::Math::IBaseFunctionMultiDimTempl< double >

Member Typedef Documentation

◆ BackendType

typedef double ROOT::Math::IBaseFunctionMultiDimTempl< double >::BackendType
inherited

Definition at line 67 of file IFunction.h.

◆ BaseFunc

Definition at line 68 of file IFunction.h.

Constructor & Destructor Documentation

◆ Functor() [1/3]

ROOT::Math::Functor::Functor ( )
inline

Default constructor.

Definition at line 54 of file Functor.h.

◆ Functor() [2/3]

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

Construct from a pointer to member function (multi-dim type).

Definition at line 58 of file Functor.h.

◆ Functor() [3/3]

ROOT::Math::Functor::Functor ( std::function< double(double const *)> const & f,
unsigned int dim )
inline

Construct from a callable object of multi-dimension with the right signature (implementing double operator()(const double *x)).

Definition at line 64 of file Functor.h.

Member Function Documentation

◆ Clone()

Functor * ROOT::Math::Functor::Clone ( ) const
inlineoverridevirtual

Clone a function.

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

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

Definition at line 67 of file Functor.h.

◆ Derivative() [1/2]

double ROOT::Math::IBaseFunctionMultiDimTempl< double >::Derivative ( const double * x,
unsigned int icoord,
double * previous_grad,
double * previous_g2,
double * previous_gstep ) const
inlineinherited

In some cases, the derivative algorithm will use information from the previous step, these can be passed in with this overload.

The previous_* arrays can also be used to return second derivative and step size so that these can be passed forward again as well at the call site, if necessary.

Definition at line 120 of file IFunction.h.

◆ Derivative() [2/2]

double ROOT::Math::IBaseFunctionMultiDimTempl< double >::Derivative ( const double * x,
unsigned int icoord = 0 ) const
inlineinherited

Return the partial derivative with respect to the passed coordinate.

Definition at line 115 of file IFunction.h.

◆ DoDerivative()

virtual double ROOT::Math::IBaseFunctionMultiDimTempl< double >::DoDerivative ( const double * ,
unsigned int  ) const
inlineprivatevirtualinherited

Function to evaluate the derivative with respect each coordinate. To be implemented by the derived class.

Reimplemented in ROOT::Math::GradFunctor, ROOT::Math::LSResidualFunc< Func >, ROOT::Math::MinimTransformFunction, and ROOT::Math::MultiNumGradFunction.

Definition at line 131 of file IFunction.h.

◆ DoDerivativeWithPrevResult()

virtual double ROOT::Math::IBaseFunctionMultiDimTempl< double >::DoDerivativeWithPrevResult ( const double * x,
unsigned int icoord,
double * ,
double * ,
double *  ) const
inlineprivatevirtualinherited

In some cases, the derivative algorithm will use information from the previous step, these can be passed in with this overload.

The previous_* arrays can also be used to return second derivative and step size so that these can be passed forward again as well at the call site, if necessary.

Definition at line 136 of file IFunction.h.

◆ DoEval()

double ROOT::Math::Functor::DoEval ( const double * x) const
inlineoverrideprivatevirtual

Implementation of the evaluation function. Must be implemented by derived classes.

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

Definition at line 74 of file Functor.h.

◆ FdF()

virtual void ROOT::Math::IBaseFunctionMultiDimTempl< double >::FdF ( const double * x,
double & f,
double * 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

Reimplemented in ROOT::Math::LSResidualFunc< Func >.

Definition at line 108 of file IFunction.h.

◆ Gradient()

virtual void ROOT::Math::IBaseFunctionMultiDimTempl< double >::Gradient ( const double * x,
double * 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 evaluating one at a time

Reimplemented in ROOT::Math::GradFunctor, and ROOT::Math::LSResidualFunc< Func >.

Definition at line 96 of file IFunction.h.

◆ HasGradient()

virtual bool ROOT::Math::IBaseFunctionMultiDimTempl< double >::HasGradient ( ) const
inlinevirtualinherited

Reimplemented in ROOT::Math::IGradientFunctionMultiDimTempl< double >.

Definition at line 92 of file IFunction.h.

◆ NDim()

unsigned int ROOT::Math::Functor::NDim ( ) const
inlineoverridevirtual

Retrieve the dimension of the function.

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

Definition at line 70 of file Functor.h.

◆ operator()()

double ROOT::Math::IBaseFunctionMultiDimTempl< double >::operator() ( const double * 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 81 of file IFunction.h.

Member Data Documentation

◆ fDim

unsigned int ROOT::Math::Functor::fDim
private

Definition at line 78 of file Functor.h.

◆ fFunc

std::function<double(double const *)> ROOT::Math::Functor::fFunc
private

Definition at line 79 of file Functor.h.


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