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

Description

GradFunctor1D class for one-dimensional gradient functions. It is used to wrap in a very C++ callable object to make a 1D gradient functions. It can be constructed in three different way:

  1. from an object implementing both double operator()( double ) for the function evaluation and double Derivative(double ) for the partial derivatives
  2. from an object implementing any member function like Foo::XXX(double ) for the function evaluation and any other member function like Foo::YYY(double ) for the derivative.
  3. from an 2 function objects implementing double operator()( double ) . One object provides the function evaluation, the other the derivative.

Definition at line 689 of file Functor.h.

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

Public Types

typedef IBaseFunctionOneDim BaseFunc
 
typedef IGradientOneDim BaseGrad
 
typedef FunctorImpl< IGradientFunctionOneDimImpl
 
typedef IGradientFunctionOneDim::BaseFunc ImplBase
 

Public Member Functions

 GradFunctor1D ()
 
template<typename Func >
 GradFunctor1D (const Func &f)
 
template<typename Func , typename GradFunc >
 GradFunctor1D (const Func &f, const GradFunc &g)
 
 GradFunctor1D (const GradFunctor1D &rhs)
 
template<class PtrObj , typename MemFn , typename GradMemFn >
 GradFunctor1D (const PtrObj &p, MemFn memFn, GradMemFn gradFn)
 
virtual ~GradFunctor1D ()
 
ImplBaseClone () const
 
double Derivative (const double *x) const
 
double Derivative (double x) const
 
void FdF (const double *x, double &f, double *df) const
 
virtual void FdF (double x, double &f, double &df) const
 
void Gradient (const double *x, double *g) const
 
double operator() (const double *x) const
 
double operator() (double x) const
 
GradFunctor1Doperator= (const GradFunctor1D &rhs)
 

Private Member Functions

double DoDerivative (double x) const
 
double DoEval (double x) const
 implementation of the evaluation function. Must be implemented by derived classes More...
 

Private Attributes

std::unique_ptr< ImplfImpl
 

Member Typedef Documentation

◆ BaseFunc

◆ BaseGrad

Definition at line 389 of file IFunction.h.

◆ Impl

◆ ImplBase

Constructor & Destructor Documentation

◆ GradFunctor1D() [1/5]

ROOT::Math::GradFunctor1D::GradFunctor1D ( )
inline

Default constructor

Definition at line 701 of file Functor.h.

701 {}

Referenced by Clone().

◆ GradFunctor1D() [2/5]

template<typename Func >
ROOT::Math::GradFunctor1D::GradFunctor1D ( const Func &  f)
inline

construct from an object with the right signature implementing both operator() (double x) and Derivative(double x)

Definition at line 709 of file Functor.h.

709  :
710  fImpl(new FunctorHandler<GradFunctor1D,Func>(f) )
711  {}
std::unique_ptr< Impl > fImpl
Definition: Functor.h:778

◆ GradFunctor1D() [3/5]

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

construct from a pointer to class and two pointers to member functions, one for the function evaluation and the other for the derivative. The member functions must take a double as argument and return a double

Definition at line 720 of file Functor.h.

721  : fImpl(new MemGradFunHandler<GradFunctor1D, PtrObj, MemFn, GradMemFn>(p, memFn, gradFn))
722  {}

◆ GradFunctor1D() [4/5]

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

construct from two 1D function objects

Definition at line 730 of file Functor.h.

730  :
731  fImpl(new FunctorGradHandler<GradFunctor1D,Func, GradFunc>(f, g) )
732  {}

◆ ~GradFunctor1D()

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

Destructor (no operations)

Definition at line 737 of file Functor.h.

737 {}

◆ GradFunctor1D() [5/5]

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

Copy constructor for Functor based on ROOT::Math::IGradFunction

Definition at line 743 of file Functor.h.

743  :
744  // strange that this is required eventhough Impl is an abstract class
745  ImplBase()
746  {
747  if (rhs.fImpl)
748  fImpl = std::unique_ptr<Impl>( rhs.fImpl->Copy() );
749  }
IGradientFunctionOneDim::BaseFunc ImplBase
Definition: Functor.h:695

References fImpl.

Member Function Documentation

◆ Clone()

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

Clone a function. Each derived class will implement their version of the provate DoClone method

Implements ROOT::Math::IBaseFunctionOneDim.

Definition at line 763 of file Functor.h.

763 { return new GradFunctor1D(*this); }

References GradFunctor1D().

Here is the call graph for this function:

◆ Derivative() [1/2]

double ROOT::Math::IGradientOneDim::Derivative ( const double *  x) const
inlineinherited

Compatibility method with multi-dimensional interface for partial derivative

Definition at line 277 of file IFunction.h.

278  {
279  return DoDerivative(*x);
280  }
virtual double DoDerivative(double x) const =0

References ROOT::Math::IGradientOneDim::DoDerivative().

Here is the call graph for this function:

◆ Derivative() [2/2]

double ROOT::Math::IGradientOneDim::Derivative ( double  x) const
inlineinherited

Return the derivative of the function at a point x Use the private method DoDerivative

Definition at line 258 of file IFunction.h.

259  {
260  return DoDerivative(x);
261  }

References ROOT::Math::IGradientOneDim::DoDerivative().

Referenced by ROOT::Math::IGradientFunctionOneDim::FdF().

Here is the call graph for this function:

◆ DoDerivative()

double ROOT::Math::GradFunctor1D::DoDerivative ( double  x) const
inlineprivatevirtual

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

Implements ROOT::Math::IGradientOneDim.

Definition at line 774 of file Functor.h.

774  {
775  return fImpl->Derivative(x);
776  }

References fImpl.

◆ DoEval()

double ROOT::Math::GradFunctor1D::DoEval ( double  x) const
inlineprivatevirtual

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

Implements ROOT::Math::IBaseFunctionOneDim.

Definition at line 769 of file Functor.h.

769  {
770  return (*fImpl)(x);
771  }

References fImpl.

◆ FdF() [1/2]

void ROOT::Math::IGradientOneDim::FdF ( const double *  x,
double &  f,
double *  df 
) const
inlineinherited

Compatibility method with multi-dimensional interface for Gradient and function evaluation

Definition at line 293 of file IFunction.h.

294  {
295  FdF(*x, f, *df);
296  }
virtual void FdF(double x, double &f, double &df) const =0

References ROOT::Math::IGradientOneDim::FdF().

Here is the call graph for this function:

◆ FdF() [2/2]

virtual void ROOT::Math::IGradientFunctionOneDim::FdF ( 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

Implements ROOT::Math::IGradientOneDim.

Definition at line 405 of file IFunction.h.

406  {
407  f = operator()(x);
408  df = Derivative(x);
409  }
double operator()(double x) const
Definition: IFunction.h:158
double Derivative(double x) const
Definition: IFunction.h:258

References ROOT::Math::IGradientOneDim::Derivative(), and ROOT::Math::IBaseFunctionOneDim::operator()().

Here is the call graph for this function:

◆ Gradient()

void ROOT::Math::IGradientOneDim::Gradient ( const double *  x,
double *  g 
) const
inlineinherited

Compatibility method with multi-dimensional interface for Gradient

Definition at line 285 of file IFunction.h.

286  {
287  g[0] = DoDerivative(*x);
288  }

References ROOT::Math::IGradientOneDim::DoDerivative().

Here is the call graph for this function:

◆ operator()() [1/2]

double ROOT::Math::IBaseFunctionOneDim::operator() ( const double *  x) const
inlineinherited

Evaluate the function at a point x[]. Compatible method with multi-dimensional functions

Definition at line 167 of file IFunction.h.

168  {
169  return DoEval(*x);
170  }
virtual double DoEval(double x) const =0
implementation of the evaluation function. Must be implemented by derived classes

References ROOT::Math::IBaseFunctionOneDim::DoEval().

Here is the call graph for this function:

◆ operator()() [2/2]

double ROOT::Math::IBaseFunctionOneDim::operator() ( double  x) const
inlineinherited

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

Definition at line 158 of file IFunction.h.

159  {
160  return DoEval(x);
161  }

References ROOT::Math::IBaseFunctionOneDim::DoEval().

Referenced by ROOT::Math::IGradientFunctionOneDim::FdF().

Here is the call graph for this function:

◆ operator=()

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

Assignment operator

Definition at line 755 of file Functor.h.

755  {
756  GradFunctor1D copy(rhs);
757  fImpl.swap(copy.fImpl);
758  return *this;
759  }

References fImpl.

Member Data Documentation

◆ fImpl

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

Definition at line 778 of file Functor.h.

Referenced by GradFunctor1D(), DoDerivative(), DoEval(), and operator=().


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