14#ifndef ROOT_Math_Functor
15#define ROOT_Math_Functor
57 template <
class PtrObj,
typename MemFn>
59 :
fDim{
dim},
fFunc{std::bind(memFn, p, std::placeholders::_1)}
70 unsigned int NDim()
const override {
return fDim; }
74 inline double DoEval (
const double *
x)
const override {
109 template <
class PtrObj,
typename MemFn>
110 Functor1D(
const PtrObj& p, MemFn memFn) :
fFunc{std::bind(memFn, p, std::placeholders::_1)} {}
117 inline double DoEval (
double x)
const override {
157 template <
typename Func>
163 template <
class PtrObj,
typename MemFn,
typename DerivMemFn,
164 std::enable_if_t<std::is_floating_point<
decltype((std::declval<std::remove_pointer_t<PtrObj>>().*
165 std::declval<DerivMemFn>())(
166 std::declval<const double *>(), std::declval<int>()))>::value,
170 fFunc{std::bind(memFn, p, std::placeholders::_1)},
171 fDerivFunc{std::bind(gradFn, p, std::placeholders::_1, std::placeholders::
_2)}
177 class PtrObj,
typename MemFn,
typename GradMemFn,
178 std::enable_if_t<std::is_void<
decltype((std::declval<std::remove_pointer_t<PtrObj>>().*std::declval<GradMemFn>())(
179 std::declval<const double *>(), std::declval<double *>()))>::value,
183 fFunc{std::bind(memFn, p, std::placeholders::_1)},
184 fGradFunc{std::bind(gradFn, p, std::placeholders::_1, std::placeholders::
_2)}
192 std::function<
double(
double const *,
unsigned int)>
const&
g,
unsigned int dim)
207 std::function<
void(
double const *,
double *)>
const&
g)
215 unsigned int NDim()
const override {
return fDim; }
229 inline double DoEval (
const double *
x)
const override {
233 inline double DoDerivative (
const double *
x,
unsigned int icoord )
const override {
239 std::vector<double> gradBuffer(
fDim);
240 std::fill(gradBuffer.begin(), gradBuffer.end(), 0.0);
242 return gradBuffer[icoord];
280 template <
typename Func>
288 template <
class PtrObj,
typename MemFn,
typename GradMemFn>
290 :
fFunc{std::bind(memFn, p, std::placeholders::_1)},
fDerivFunc{std::bind(gradFn, p, std::placeholders::_1)}
297 GradFunctor1D(std::function<
double(
double)>
const&
f, std::function<
double(
double)>
const&
g)
Functor1D()=default
Default constructor.
std::function< double(double)> fFunc
double DoEval(double x) const override
implementation of the evaluation function. Must be implemented by derived classes
Functor1D * Clone() const override
Clone a function.
Functor1D(const PtrObj &p, MemFn memFn)
Functor1D(std::function< double(double)> const &f)
Construct from a callable object with the right signature implementing double operator() (double x).
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 ope...
Functor()
Default constructor.
std::function< double(double const *)> fFunc
double DoEval(const double *x) const override
Implementation of the evaluation function. Must be implemented by derived classes.
Functor * Clone() const override
Clone a function.
unsigned int NDim() const override
Retrieve the dimension of the function.
Functor(const PtrObj &p, MemFn memFn, unsigned int dim)
Construct from a pointer to member function (multi-dim type).
GradFunctor1D(std::function< double(double)> const &f, std::function< double(double)> const &g)
Specialized constructor from 2 function objects implementing double operator()(double x).
GradFunctor1D * Clone() const override
Clone a function.
std::function< double(double)> fFunc
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...
GradFunctor1D(const Func &f)
Construct from an object with the right signature, implementing both operator() (double x) and Deriva...
double DoDerivative(double x) const override
Function to evaluate the derivative with respect each coordinate. To be implemented by the derived cl...
std::function< double(double)> fDerivFunc
double DoEval(double x) const override
implementation of the evaluation function. Must be implemented by derived classes
GradFunctor1D()=default
Default constructor.
void Gradient(const double *x, double *g) const override
Evaluate all the vector of function derivatives (gradient) at a point x.
std::function< double(double const *, unsigned int)> fDerivFunc
GradFunctor(const PtrObj &p, MemFn memFn, DerivMemFn gradFn, unsigned int dim)
Construct from a pointer to member function and member function types for function and derivative eva...
unsigned int NDim() const override
Retrieve the dimension of the function.
GradFunctor * Clone() const override
Clone a function.
double DoEval(const double *x) const override
Implementation of the evaluation function. Must be implemented by derived classes.
GradFunctor()=default
Default constructor.
GradFunctor(std::function< double(double const *)> const &f, std::function< double(double const *, unsigned int)> const &g, unsigned int dim)
Construct for Gradient Functions of multi-dimension Func gives the function evaluation,...
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 full derivati...
GradFunctor(const Func &f, unsigned int dim)
construct from a callable object of multi-dimension implementing operator()(const double *x) and Deri...
GradFunctor(std::function< double(double const *)> const &f, unsigned int dim, std::function< void(double const *, double *)> const &g)
Construct a new GradFunctor object using 2 std::function, one for the function evaluation and one for...
std::function< void(const double *, double *)> fGradFunc
double DoDerivative(const double *x, unsigned int icoord) const override
Function to evaluate the derivative with respect each coordinate. To be implemented by the derived cl...
std::function< double(const double *)> fFunc
virtual void Gradient(const double *x, double *grad) const
double Derivative(const double *x, unsigned int icoord=0) const
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
double Derivative(double x) const
Return the derivative of the function at a point x Use the private method DoDerivative.
Interface (abstract class) for one-dimensional functions providing a gradient calculation.
IGradientFunctionMultiDimTempl< double > IGradientFunctionMultiDim
IBaseFunctionMultiDimTempl< double > IBaseFunctionMultiDim