Logo ROOT   6.08/07
Reference Guide
Functor.h
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Author: L. Moneta Mon Nov 13 15:58:13 2006
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7  * *
8  * *
9  **********************************************************************/
10 
11 // Heaer file for Functor classes.
12 // designed is inspired by the Loki Functor
13 
14 #ifndef ROOT_Math_Functor
15 #define ROOT_Math_Functor
16 
17 #ifndef ROOT_Math_IFunction
18 #include "Math/IFunction.h"
19 #endif
20 
21 // #ifndef Root_Math_StaticCheck
22 // #include "Math/StaticCheck.h"
23 // #endif
24 
25 #include <memory>
26 
27 
28 namespace ROOT {
29 
30 namespace Math {
31 
32 /**
33  @defgroup Functor_int Internal Functor Classes
34  Internal classes for implementing Functor and Functor1D classes
35  @ingroup GenFunc
36  */
37 
38 /**
39  FunctorImpl is a base class for the functor
40  handler implementation class.
41  It defines the Copy operator used to clone the functor objects
42 */
43 
44 template<class IBaseFunc>
45 class FunctorImpl : public IBaseFunc {
46 
47 public:
48 
49  typedef IBaseFunc BaseFunc;
50 
51 
52  FunctorImpl() : IBaseFunc() { }
53 
54  virtual ~FunctorImpl() {}
55 
56  virtual FunctorImpl* Copy() const = 0;
57 
58 };
59 
60 /**
61  Functor Handler class is responsible for wrapping any other functor and pointer to
62  free C functions.
63  It can be created from any function implementing the correct signature
64  corresponding to the requested type
65  In the case of one dimension the function evaluation object must implement
66  double operator() (double x). If it implements a method: double Derivative(double x)
67  can be used to create a Gradient function type.
68 
69  In the case of multi-dimension the function evaluation object must implement
70  double operator()(const double *x). If it implements a method:
71  double Derivative(const double *x, int icoord)
72  can be used to create a Gradient function type.
73 
74  @ingroup Functor_int
75 
76 */
77 template<class ParentFunctor, class Func >
78 class FunctorHandler : public ParentFunctor::Impl {
79 
80  typedef typename ParentFunctor::Impl ImplFunc;
81  typedef typename ImplFunc::BaseFunc BaseFunc;
82  //typedef typename ParentFunctor::Dim Dim;
83 
84 
85 public:
86 
87  // constructor for 1d functions
88  FunctorHandler(const Func & fun) : fDim(1), fFunc(fun) {}
89 
90 
91  // constructor for multi-dimensional functions w/0 NDim()
92  FunctorHandler(unsigned int dim, const Func & fun ) :
93  fDim(dim),
94  fFunc(fun)
95  {}
96 
97  virtual ~FunctorHandler() {}
98 
99  // copy of the function handler (use copy-ctor)
100  ImplFunc * Copy() const {
101  return new FunctorHandler(*this);
102  }
103 
104  // clone of the function handler (use copy-ctor)
105  BaseFunc * Clone() const {
106  return Copy();
107  }
108 
109 
110  // constructor for multi-dimensional functions
111  unsigned int NDim() const {
112  return fDim;
113  }
114 
115 private :
116 
117  inline double DoEval (double x) const {
118  return fFunc(x);
119  }
120 
121  inline double DoEval (const double * x) const {
122  return fFunc(x);
123  }
124 
125  inline double DoDerivative (double x) const {
126  return fFunc.Derivative(x);
127  }
128 
129  inline double DoDerivative (const double * x, unsigned int icoord ) const {
130  return fFunc.Derivative(x,icoord);
131  }
132 
133 
134  unsigned int fDim;
135  mutable Func fFunc; // should here be a reference and pass a non-const ref in ctor
136 
137 };
138 
139 
140 /**
141  Functor Handler class for gradient functions where both callable objects are provided for the function
142  evaluation (type Func) and for the gradient (type GradFunc) .
143  It can be created from any function implementing the correct signature
144  corresponding to the requested type
145  In the case of one dimension the function evaluation object and the derivative function object must implement
146  double operator() (double x).
147  In the case of multi-dimension the function evaluation object must implement
148  double operator() (const double * x) and the gradient function object must implement
149  double operator() (const double * x, int icoord)
150 
151  @ingroup Functor_int
152 */
153 template<class ParentFunctor, class Func, class GradFunc >
154 class FunctorGradHandler : public ParentFunctor::Impl {
155 
156  typedef typename ParentFunctor::Impl ImplFunc;
157  typedef typename ImplFunc::BaseFunc BaseFunc;
158  //typedef typename ParentFunctor::Dim Dim;
159 
160 public:
161 
162  // constructor for 1d functions
163  FunctorGradHandler(const Func & fun, const GradFunc & gfun) :
164  fDim(1),
165  fFunc(fun),
166  fGradFunc(gfun)
167  {}
168 
169 
170  // constructor for multi-dimensional functions
171  FunctorGradHandler(unsigned int dim, const Func & fun, const GradFunc & gfun) :
172  fDim(dim),
173  fFunc(fun),
174  fGradFunc( gfun )
175  {}
176 
177  virtual ~FunctorGradHandler() {}
178 
179  // clone of the function handler (use copy-ctor)
180  ImplFunc * Copy() const { return new FunctorGradHandler(*this); }
181 
182  // clone of the function handler (use copy-ctor)
183  BaseFunc * Clone() const { return Copy(); }
184 
185  // constructor for multi-dimensional functions
186  unsigned int NDim() const {
187  return fDim;
188  }
189 
190 private :
191 
192  inline double DoEval (double x) const {
193  return fFunc(x);
194  }
195 
196  inline double DoEval (const double * x) const {
197  return fFunc(x);
198  }
199 
200  inline double DoDerivative (double x) const {
201  return fGradFunc(x);
202  }
203 
204  inline double DoDerivative (const double * x, unsigned int icoord ) const {
205  return fGradFunc(x, icoord);
206  }
207 
208 
209  unsigned int fDim;
210  mutable Func fFunc;
211  mutable GradFunc fGradFunc;
212 
213 };
214 
215 
216 /**
217  Functor Handler to Wrap pointers to member functions
218  The member function type must be (XXX means any name is allowed) :
219  double XXX ( double x) for 1D functions
220  and
221  double XXXX (const double *x) for multi-dimensional functions
222 
223  @ingroup Functor_int
224 */
225 template <class ParentFunctor, typename PointerToObj,
226  typename PointerToMemFn>
227 class MemFunHandler : public ParentFunctor::Impl
228 {
229  //typedef typename ParentFunctor::Dim Dim;
230  typedef typename ParentFunctor::Impl ImplFunc;
231  typedef typename ImplFunc::BaseFunc BaseFunc;
232 
233 public:
234 
235  /// constructor from a pointer to the class and a pointer to the function
236  MemFunHandler(const PointerToObj& pObj, PointerToMemFn pMemFn)
237  : fDim(1), fObj(pObj), fMemFn(pMemFn) // should pass pointer by value ??
238  {}
239 
240  /// constructor from a pointer to the class and a pointer to the function
241  MemFunHandler(unsigned int dim, const PointerToObj& pObj, PointerToMemFn pMemFn)
242  : fDim(dim), fObj(pObj), fMemFn(pMemFn)
243  {}
244 
245  virtual ~MemFunHandler() {}
246 
247  // clone of the function handler (use copy-ctor)
248  ImplFunc * Copy() const { return new MemFunHandler(*this); }
249 
250  // clone of the function handler (use copy-ctor)
251  BaseFunc * Clone() const { return new MemFunHandler(*this); }
252 
253  // constructor for multi-dimensional functions
254  unsigned int NDim() const {
255  return fDim;
256  }
257 
258 private :
259 
260  inline double DoEval (double x) const {
261  return ((*fObj).*fMemFn)(x);
262  }
263 
264  inline double DoEval (const double * x) const {
265  return ((*fObj).*fMemFn)(x);
266  }
267 
268  unsigned int fDim;
269  mutable PointerToObj fObj;
270  PointerToMemFn fMemFn;
271 
272 };
273 
274 /**
275  Functor Handler to Wrap pointers to member functions for the evaluation of the function
276  and the gradient.
277  The member function type must be (XXX means any name is allowed) :
278  double XXX ( double x) for 1D function and derivative evaluation
279  double XXX (const double *x) for multi-dimensional function evaluation and
280  double XXX (cost double *x, int icoord) for partial derivatives evaluation
281 
282  @ingroup Functor_int
283 
284 */
285 template <class ParentFunctor, typename PointerToObj,
286  typename PointerToMemFn, typename PointerToGradMemFn>
287 class MemGradFunHandler : public ParentFunctor::Impl
288 {
289  typedef typename ParentFunctor::Impl ImplFunc;
290  typedef typename ImplFunc::BaseFunc BaseFunc;
291  //typedef typename ParentFunctor::Dim Dim;
292 
293 public:
294 
295  /// constructor from a pointer to the class and a pointer to the function
296  MemGradFunHandler(const PointerToObj& pObj, PointerToMemFn pMemFn, PointerToGradMemFn pGradMemFn)
297  : fDim(1),
298  fObj(pObj),
299  fMemFn(pMemFn),
300  fGradMemFn(pGradMemFn)
301  {}
302 
303  /// constructor from a pointer to the class and a pointer to the function
304  MemGradFunHandler(unsigned int dim,
305  const PointerToObj& pObj,
306  PointerToMemFn pMemFn,
307  PointerToGradMemFn pGradMemFn )
308  : fDim(dim),
309  fObj(pObj),
310  fMemFn(pMemFn),
311  fGradMemFn(pGradMemFn)
312  {}
313 
314  virtual ~MemGradFunHandler() {}
315 
316  // clone of the function handler (use copy-ctor)
317  ImplFunc * Copy() const { return new MemGradFunHandler(*this); }
318 
319  // clone of the function handler (use copy-ctor)
320  BaseFunc * Clone() const { return new MemGradFunHandler(*this); }
321 
322  // constructor for multi-dimensional functions
323  unsigned int NDim() const {
324  return fDim;
325  }
326 
327 private :
328 
329  inline double DoEval (double x) const {
330  return ((*fObj).*fMemFn)(x);
331  }
332 
333  inline double DoEval (const double * x) const {
334  return ((*fObj).*fMemFn)(x);
335  }
336 
337  inline double DoDerivative (double x) const {
338  return ((*fObj).*fGradMemFn)(x);
339  }
340 
341  inline double DoDerivative (const double * x, unsigned int icoord ) const {
342  return ((*fObj).*fGradMemFn)(x,icoord);
343  }
344 
345  unsigned int fDim;
346  mutable PointerToObj fObj;
347  PointerToMemFn fMemFn;
348  PointerToGradMemFn fGradMemFn;
349 };
350 
351 
352 //****************************
353 // LM 7/2/2014: no needed this : make template ctor of Functor1D and GradFunctor1D not
354 // available to CINT s
355 //***************************************
356 //#if defined(__MAKECINT__) || defined(G__DICTIONARY)
357 // needed since CINT initialize it with TRootIOCtor
358 //class TRootIOCtor;
359 
360 // template<class ParentFunctor>
361 // class FunctorHandler<ParentFunctor,TRootIOCtor *> : public ParentFunctor::Impl
362 // {
363 // public:
364 // typedef typename ParentFunctor::Impl ImplFunc;
365 // typedef typename ImplFunc::BaseFunc BaseFunc;
366 
367 // FunctorHandler(TRootIOCtor *) {}
368 // // function required by interface
369 // virtual ~FunctorHandler() {}
370 // double DoEval (double ) const { return 0; }
371 // double DoDerivative (double ) const { return 0; }
372 // ImplFunc * Copy() const { return 0; }
373 // BaseFunc * Clone() const { return 0; }
374 
375 // };
376 // #endif
377 
378 
379 /**
380  Documentation for class Functor class.
381  It is used to wrap in a very simple and convenient way multi-dimensional function objects.
382  It can wrap all the following types:
383  <ul>
384  <li> any C++ callable object implemention double operator()( const double * )
385  <li> a free C function of type double ()(const double * )
386  <li> a member function with the correct signature like Foo::Eval(const double * ).
387  In this case one pass the object pointer and a pointer to the member function (&Foo::Eval)
388  </ul>
389  The function dimension is required when constructing the functor.
390 
391  @ingroup GenFunc
392 
393  */
395 
396 
397 public:
398 
401 
402  /**
403  Default constructor
404  */
405  Functor () {}
406 
407 
408  /**
409  construct from a pointer to member function (multi-dim type)
410  */
411  template <class PtrObj, typename MemFn>
412  Functor(const PtrObj& p, MemFn memFn, unsigned int dim )
413  : fImpl(new MemFunHandler<Functor, PtrObj, MemFn>(dim, p, memFn))
414  {}
415 
416 
417 
418  /**
419  construct from a callable object of multi-dimension
420  with the right signature (implementing operator()(double *x)
421  */
422  template <typename Func>
423  Functor( const Func & f, unsigned int dim ) :
424  fImpl(new FunctorHandler<Functor,Func>(dim,f) )
425  {}
426 
427 
428  /**
429  Destructor (no operations)
430  */
431  virtual ~Functor () {}
432 
433  /**
434  Copy constructor for functor based on ROOT::Math::IMultiGenFunction
435  */
436  Functor(const Functor & rhs) :
437  ImplBase()
438  {
439  if (rhs.fImpl)
440  fImpl = std::unique_ptr<Impl>( (rhs.fImpl)->Copy() );
441  }
442  // need a specialization in order to call base classes and use clone
443 
444 
445  /**
446  Assignment operator
447  */
448  Functor & operator = (const Functor & rhs) {
449  Functor copy(rhs);
450  // swap the poiter
451  fImpl.swap( copy.fImpl);
452  // // swap unique_ptr by hand
453  // Impl * p = fImpl.release();
454  // fImpl.reset(copy.fImpl.release());
455  // copy.fImpl.reset(p);
456  return *this;
457  }
458 
459 
460  // clone of the function handler (use copy-ctor)
461  ImplBase * Clone() const { return new Functor(*this); }
462 
463  // for multi-dimensional functions
464  unsigned int NDim() const { return fImpl->NDim(); }
465 
466 private :
467 
468 
469  inline double DoEval (const double * x) const {
470  return (*fImpl)(x);
471  }
472 
473 
474  std::unique_ptr<Impl> fImpl; // pointer to base functor handler
475 
476 
477 };
478 
479 /**
480  Functor1D class for one-dimensional functions.
481  It is used to wrap in a very simple and convenient way:
482  <ul>
483  <li> any C++ callable object implemention double operator()( double )
484  <li> a free C function of type double ()(double )
485  <li> a member function with the correct signature like Foo::Eval(double ).
486  In this case one pass the object pointer and a pointer to the member function (&Foo::Eval)
487  </ul>
488 
489 
490  @ingroup GenFunc
491 
492  */
493 
495 
496 
497 public:
498 
501 
502  /**
503  Default constructor
504  */
505  Functor1D () {}
506 
507  /**
508  construct from a callable object with the right signature
509  implementing operator() (double x)
510  */
511  template <typename Func>
512  Functor1D(const Func & f) :
513  fImpl(new FunctorHandler<Functor1D,Func>(f) )
514  {}
515 
516 
517  /**
518  construct from a pointer to member function (1D type)
519  */
520  template <class PtrObj, typename MemFn>
521  Functor1D(const PtrObj& p, MemFn memFn)
522  : fImpl(new MemFunHandler<Functor1D, PtrObj, MemFn>(p, memFn))
523  {}
524 
525 
526  /**
527  Destructor (no operations)
528  */
529  virtual ~Functor1D () {}
530 
531 
532  /**
533  Copy constructor for Functor based on ROOT::Math::IGenFunction
534  */
535  Functor1D(const Functor1D & rhs) :
536  // strange that this is required eventhough ImplBase is an abstract class
537  ImplBase()
538  {
539  if (rhs.fImpl)
540  fImpl = std::unique_ptr<Impl>( (rhs.fImpl)->Copy() );
541  }
542 
543 
544  /**
545  Assignment operator
546  */
547  Functor1D & operator = (const Functor1D & rhs) {
548  Functor1D copy(rhs);
549  fImpl.swap( copy.fImpl);
550  // swap auto_ptr by hand
551  // Impl * p = fImpl.release();
552  // fImpl.reset(copy.fImpl.release());
553  // copy.fImpl.reset(p);
554  return *this;
555  }
556 
557 
558  // clone of the function handler (use copy-ctor)
559  ImplBase * Clone() const { return new Functor1D(*this); }
560 
561 
562 private :
563 
564  inline double DoEval (double x) const {
565  return (*fImpl)(x);
566  }
567 
568 
569  std::unique_ptr<Impl> fImpl; // pointer to base functor handler
570 
571 
572 };
573 
574 /**
575  GradFunctor class for Multidimensional gradient functions.
576  It is used to wrap in a very C++ callable object to make gradient functions.
577  It can be constructed in three different way:
578  <ol>
579  <li> from an object implementing both
580  double operator()( const double * ) for the function evaluation and
581  double Derivative(const double *, int icoord) for the partial derivatives
582  <li>from an object implementing any member function like Foo::XXX(const double *) for the function evaluation
583  and any member function like Foo::XXX(const double *, int icoord) for the partial derivatives
584  <li>from an function object implementing
585  double operator()( const double * ) for the function evaluation and another function object implementing
586  double operator() (const double *, int icoord) for the partial derivatives
587  </ol>
588  The function dimension is required when constructing the functor.
589 
590  @ingroup GenFunc
591 
592  */
594 
595 
596 public:
597 
600 
601 
602  /**
603  Default constructor
604  */
606 
607  /**
608  construct from a callable object of multi-dimension
609  implementing operator()(const double *x) and
610  Derivative(const double * x,icoord)
611  */
612  template <typename Func>
613  GradFunctor( const Func & f, unsigned int dim ) :
614  fImpl(new FunctorHandler<GradFunctor,Func>(dim,f) )
615  {}
616 
617  /**
618  construct from a pointer to member function and member function types for function and derivative evaluations
619  */
620  template <class PtrObj, typename MemFn, typename GradMemFn>
621  GradFunctor(const PtrObj& p, MemFn memFn, GradMemFn gradFn, unsigned int dim )
622  : fImpl(new MemGradFunHandler<GradFunctor, PtrObj, MemFn, GradMemFn>(dim, p, memFn, gradFn))
623  {}
624 
625  /**
626  construct for Gradient Functions of multi-dimension
627  Func gives the function evaluatiion, GradFunc the partial derivatives
628  The function dimension is required
629  */
630  template <typename Func, typename GradFunc>
631  GradFunctor(const Func & f, const GradFunc & g, int dim ) :
632  fImpl(new FunctorGradHandler<GradFunctor,Func,GradFunc>(dim, f, g) )
633  { }
634 
635 
636  /**
637  Destructor (no operations)
638  */
639  virtual ~GradFunctor () {}
640 
641 
642  /**
643  Copy constructor for functor based on ROOT::Math::IMultiGradFunction
644  */
645  GradFunctor(const GradFunctor & rhs) :
646  ImplBase()
647  {
648  if (rhs.fImpl)
649  fImpl = std::unique_ptr<Impl>( rhs.fImpl->Copy() );
650  }
651 
652  /**
653  Assignment operator
654  */
655  GradFunctor & operator = (const GradFunctor & rhs) {
656  GradFunctor copy(rhs);
657  fImpl.swap(copy.fImpl);
658  // swap auto_ptr by hand
659  // Impl * p = fImpl.release();
660  // fImpl.reset(copy.fImpl.release());
661  // copy.fImpl.reset(p);
662  return *this;
663  }
664 
665 
666  // clone of the function handler (use copy-ctor)
667  ImplBase * Clone() const { return new GradFunctor(*this); }
668 
669  // for multi-dimensional functions
670  unsigned int NDim() const { return fImpl->NDim(); }
671 
672 private :
673 
674 
675  inline double DoEval (const double * x) const {
676  return (*fImpl)(x);
677  }
678 
679 
680  inline double DoDerivative (const double * x, unsigned int icoord ) const {
681  return fImpl->Derivative(x,icoord);
682  }
683 
684  std::unique_ptr<Impl> fImpl; // pointer to base grad functor handler
685 
686 
687 };
688 
689 
690 //_______________________________________________________________________________________________
691 /**
692  GradFunctor1D class for one-dimensional gradient functions.
693  It is used to wrap in a very C++ callable object to make a 1D gradient functions.
694  It can be constructed in three different way:
695  <ol>
696  <li> from an object implementing both
697  double operator()( double ) for the function evaluation and
698  double Derivative(double ) for the partial derivatives
699  <li>from an object implementing any member function like Foo::XXX(double ) for the function evaluation
700  and any other member function like Foo::YYY(double ) for the derivative.
701  <li>from an 2 function objects implementing
702  double operator()( double ) . One object provides the function evaluation, the other the derivative.
703  </ol>
704 
705  @ingroup GenFunc
706 
707  */
708 
710 
711 
712 public:
713 
716 
717 
718  /**
719  Default constructor
720  */
722 
723 
724  /**
725  construct from an object with the right signature
726  implementing both operator() (double x) and Derivative(double x)
727  */
728  template <typename Func>
729  GradFunctor1D(const Func & f) :
730  fImpl(new FunctorHandler<GradFunctor1D,Func>(f) )
731  {}
732 
733 
734  /**
735  construct from a pointer to class and two pointers to member functions, one for
736  the function evaluation and the other for the derivative.
737  The member functions must take a double as argument and return a double
738  */
739  template <class PtrObj, typename MemFn, typename GradMemFn>
740  GradFunctor1D(const PtrObj& p, MemFn memFn, GradMemFn gradFn)
741  : fImpl(new MemGradFunHandler<GradFunctor1D, PtrObj, MemFn, GradMemFn>(p, memFn, gradFn))
742  {}
743 
744 
745 
746  /**
747  construct from two 1D function objects
748  */
749  template <typename Func, typename GradFunc>
750  GradFunctor1D(const Func & f, const GradFunc & g ) :
751  fImpl(new FunctorGradHandler<GradFunctor1D,Func, GradFunc>(f, g) )
752  {}
753 
754  /**
755  Destructor (no operations)
756  */
757  virtual ~GradFunctor1D () {}
758 
759 
760  /**
761  Copy constructor for Functor based on ROOT::Math::IGradFunction
762  */
764  // strange that this is required eventhough Impl is an abstract class
765  ImplBase()
766  {
767  if (rhs.fImpl)
768  fImpl = std::unique_ptr<Impl>( rhs.fImpl->Copy() );
769  }
770 
771 
772  /**
773  Assignment operator
774  */
775  GradFunctor1D & operator = (const GradFunctor1D & rhs) {
776  GradFunctor1D copy(rhs);
777  fImpl.swap(copy.fImpl);
778  // swap auto_ptr by hand
779  // Impl * p = fImpl.release();
780  // fImpl.reset(copy.fImpl.release());
781  // copy.fImpl.reset(p);
782  return *this;
783  }
784 
785 
786  // clone of the function handler (use copy-ctor)
787  ImplBase * Clone() const { return new GradFunctor1D(*this); }
788 
789 
790 private :
791 
792 
793  inline double DoEval (double x) const {
794  return (*fImpl)(x);
795  }
796 
797 
798  inline double DoDerivative (double x) const {
799  return fImpl->Derivative(x);
800  }
801 
802  std::unique_ptr<Impl> fImpl; // pointer to base gradient functor handler
803 
804 };
805 
806 
807 
808  } // end namespace Math
809 
810 } // end namespace ROOT
811 
812 
813 #endif /* ROOT_Math_Functor */
double DoDerivative(double x) const
Definition: Functor.h:337
FunctorHandler(const Func &fun)
Definition: Functor.h:88
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
Definition: IFunction.h:322
GradFunctor1D(const Func &f, const GradFunc &g)
construct from two 1D function objects
Definition: Functor.h:750
double DoEval(double x) const
implementation of the evaluation function. Must be implemented by derived classes ...
Definition: Functor.h:793
FunctorImpl< IBaseFunctionMultiDim > Impl
Definition: Functor.h:399
unsigned int NDim() const
Retrieve the dimension of the function.
Definition: Functor.h:464
Functor Handler class is responsible for wrapping any other functor and pointer to free C functions...
Definition: Functor.h:78
double DoEval(double x) const
Definition: Functor.h:192
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition: IFunction.h:133
FunctorImpl< IGradientFunctionMultiDim > Impl
Definition: Functor.h:598
double DoDerivative(const double *x, unsigned int icoord) const
Definition: Functor.h:129
IBaseFunc BaseFunc
Definition: Functor.h:49
MemFunHandler(const PointerToObj &pObj, PointerToMemFn pMemFn)
constructor from a pointer to the class and a pointer to the function
Definition: Functor.h:236
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
GradFunctor class for Multidimensional gradient functions.
Definition: Functor.h:593
GradFunctor1D class for one-dimensional gradient functions.
Definition: Functor.h:709
FunctorImpl< IGradientFunctionOneDim > Impl
Definition: Functor.h:714
ImplFunc * Copy() const
Definition: Functor.h:317
GradFunctor1D(const GradFunctor1D &rhs)
Copy constructor for Functor based on ROOT::Math::IGradFunction.
Definition: Functor.h:763
Documentation for class Functor class.
Definition: Functor.h:394
double DoEval(const double *x) const
Definition: Functor.h:333
virtual FunctorImpl * Copy() const =0
double DoEval(const double *x) const
Definition: Functor.h:121
BaseFunc * Clone() const
Definition: Functor.h:105
ImplBase * Clone() const
Clone a function.
Definition: Functor.h:787
IBaseFunctionOneDim::BaseFunc ImplBase
Definition: Functor.h:500
GradFunctor1D(const Func &f)
construct from an object with the right signature implementing both operator() (double x) and Derivat...
Definition: Functor.h:729
BaseFunc * Clone() const
Definition: Functor.h:320
double DoEval(const double *x) const
Definition: Functor.h:196
GradFunctor()
Default constructor.
Definition: Functor.h:605
double DoDerivative(const double *x, unsigned int icoord) const
Definition: Functor.h:204
unsigned int NDim() const
Definition: Functor.h:254
ImplBase * Clone() const
Clone a function.
Definition: Functor.h:559
std::unique_ptr< Impl > fImpl
Definition: Functor.h:802
unsigned int NDim() const
Definition: Functor.h:111
ImplFunc * Copy() const
Definition: Functor.h:180
FunctorHandler(unsigned int dim, const Func &fun)
Definition: Functor.h:92
MemGradFunHandler(const PointerToObj &pObj, PointerToMemFn pMemFn, PointerToGradMemFn pGradMemFn)
constructor from a pointer to the class and a pointer to the function
Definition: Functor.h:296
Interface (abstract class) for one-dimensional functions providing a gradient calculation.
Definition: IFunction.h:382
GradFunctor(const Func &f, const GradFunc &g, int dim)
construct for Gradient Functions of multi-dimension Func gives the function evaluatiion, GradFunc the partial derivatives The function dimension is required
Definition: Functor.h:631
double DoEval(double x) const
Definition: Functor.h:117
double DoEval(const double *x) const
Definition: Functor.h:264
GradFunctor(const Func &f, unsigned int dim)
construct from a callable object of multi-dimension implementing operator()(const double *x) and Deri...
Definition: Functor.h:613
Double_t x[n]
Definition: legend1.C:17
double DoDerivative(const double *x, unsigned int icoord) const
function to evaluate the derivative with respect each coordinate.
Definition: Functor.h:680
double DoDerivative(double x) const
Definition: Functor.h:125
ImplFunc::BaseFunc BaseFunc
Definition: Functor.h:290
FunctorGradHandler(unsigned int dim, const Func &fun, const GradFunc &gfun)
Definition: Functor.h:171
virtual ~GradFunctor()
Destructor (no operations)
Definition: Functor.h:639
Functor(const Func &f, unsigned int dim)
construct from a callable object of multi-dimension with the right signature (implementing operator()...
Definition: Functor.h:423
BaseFunc * Clone() const
Definition: Functor.h:251
ParentFunctor::Impl ImplFunc
Definition: Functor.h:230
double DoEval(double x) const
Definition: Functor.h:329
Functor1D(const Functor1D &rhs)
Copy constructor for Functor based on ROOT::Math::IGenFunction.
Definition: Functor.h:535
ParentFunctor::Impl ImplFunc
Definition: Functor.h:80
GradFunctor1D()
Default constructor.
Definition: Functor.h:721
Functor Handler to Wrap pointers to member functions The member function type must be (XXX means any ...
Definition: Functor.h:227
Functor1D(const PtrObj &p, MemFn memFn)
construct from a pointer to member function (1D type)
Definition: Functor.h:521
Functor(const PtrObj &p, MemFn memFn, unsigned int dim)
construct from a pointer to member function (multi-dim type)
Definition: Functor.h:412
double DoEval(double x) const
Definition: Functor.h:260
MemGradFunHandler(unsigned int dim, const PointerToObj &pObj, PointerToMemFn pMemFn, PointerToGradMemFn pGradMemFn)
constructor from a pointer to the class and a pointer to the function
Definition: Functor.h:304
Functor(const Functor &rhs)
Copy constructor for functor based on ROOT::Math::IMultiGenFunction.
Definition: Functor.h:436
FunctorImpl is a base class for the functor handler implementation class.
Definition: Functor.h:45
ImplFunc * Copy() const
Definition: Functor.h:100
IParamFunction interface (abstract class) describing multi-dimensional parameteric functions It is a ...
Functor1D()
Default constructor.
Definition: Functor.h:505
ImplBase * Clone() const
Clone a function.
Definition: Functor.h:667
GradFunctor(const GradFunctor &rhs)
Copy constructor for functor based on ROOT::Math::IMultiGradFunction.
Definition: Functor.h:645
std::unique_ptr< Impl > fImpl
Definition: Functor.h:474
double DoEval(double x) const
implementation of the evaluation function. Must be implemented by derived classes ...
Definition: Functor.h:564
GradFunctor(const PtrObj &p, MemFn memFn, GradMemFn gradFn, unsigned int dim)
construct from a pointer to member function and member function types for function and derivative eva...
Definition: Functor.h:621
unsigned int NDim() const
Definition: Functor.h:186
double DoDerivative(double x) const
Definition: Functor.h:200
virtual ~FunctorImpl()
Definition: Functor.h:54
ImplBase * Clone() const
Clone a function.
Definition: Functor.h:461
Functor()
Default constructor.
Definition: Functor.h:405
virtual ~FunctorHandler()
Definition: Functor.h:97
std::unique_ptr< Impl > fImpl
Definition: Functor.h:684
virtual ~Functor1D()
Destructor (no operations)
Definition: Functor.h:529
GradFunctor1D(const PtrObj &p, MemFn memFn, GradMemFn gradFn)
construct from a pointer to class and two pointers to member functions, one for the function evaluati...
Definition: Functor.h:740
double DoEval(const double *x) const
Implementation of the evaluation function.
Definition: Functor.h:469
double DoDerivative(const double *x, unsigned int icoord) const
Definition: Functor.h:341
double f(double x)
IGradientFunctionOneDim::BaseFunc ImplBase
Definition: Functor.h:715
unsigned int NDim() const
Definition: Functor.h:323
Functor1D(const Func &f)
construct from a callable object with the right signature implementing operator() (double x) ...
Definition: Functor.h:512
BaseFunc * Clone() const
Definition: Functor.h:183
virtual ~Functor()
Destructor (no operations)
Definition: Functor.h:431
Namespace for new Math classes and functions.
PointerToGradMemFn fGradMemFn
Definition: Functor.h:348
ImplFunc::BaseFunc BaseFunc
Definition: Functor.h:231
ParentFunctor::Impl ImplFunc
Definition: Functor.h:289
MemFunHandler(unsigned int dim, const PointerToObj &pObj, PointerToMemFn pMemFn)
constructor from a pointer to the class and a pointer to the function
Definition: Functor.h:241
virtual ~GradFunctor1D()
Destructor (no operations)
Definition: Functor.h:757
ParentFunctor::Impl ImplFunc
Definition: Functor.h:156
std::unique_ptr< Impl > fImpl
Definition: Functor.h:569
double DoDerivative(double x) const
function to evaluate the derivative with respect each coordinate.
Definition: Functor.h:798
ImplFunc * Copy() const
Definition: Functor.h:248
Functor Handler to Wrap pointers to member functions for the evaluation of the function and the gradi...
Definition: Functor.h:287
virtual ~MemFunHandler()
Definition: Functor.h:245
FunctorGradHandler(const Func &fun, const GradFunc &gfun)
Definition: Functor.h:163
double DoEval(const double *x) const
Implementation of the evaluation function.
Definition: Functor.h:675
Functor1D class for one-dimensional functions.
Definition: Functor.h:494
IGradientFunctionMultiDim::BaseFunc ImplBase
Definition: Functor.h:599
ImplFunc::BaseFunc BaseFunc
Definition: Functor.h:157
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:63
PointerToMemFn fMemFn
Definition: Functor.h:270
ImplFunc::BaseFunc BaseFunc
Definition: Functor.h:81
IBaseFunctionMultiDim::BaseFunc ImplBase
Definition: Functor.h:400
FunctorImpl< IBaseFunctionOneDim > Impl
Definition: Functor.h:499
Functor Handler class for gradient functions where both callable objects are provided for the functio...
Definition: Functor.h:154
unsigned int NDim() const
Retrieve the dimension of the function.
Definition: Functor.h:670