14#ifndef ROOT_Math_Functor
15#define ROOT_Math_Functor
55 template <
class PtrObj,
typename MemFn>
56 Functor(
const PtrObj&
p, MemFn memFn,
unsigned int dim )
57 :
fDim{dim},
fFunc{std::bind(memFn,
p, std::placeholders::_1)}
62 Functor(std::function<
double(
double const *)>
const&
f,
unsigned int dim ) :
fDim{dim},
fFunc{
f} {}
68 unsigned int NDim()
const override {
return fDim; }
72 inline double DoEval (
const double *
x)
const override {
107 template <
class PtrObj,
typename MemFn>
108 Functor1D(
const PtrObj&
p, MemFn memFn) :
fFunc{std::bind(memFn,
p, std::placeholders::_1)} {}
115 inline double DoEval (
double x)
const override {
155 template <
typename Func>
161 template <
class PtrObj,
typename MemFn,
typename DerivMemFn,
162 std::enable_if_t<std::is_floating_point<
decltype((std::declval<std::remove_pointer_t<PtrObj>>().*
163 std::declval<DerivMemFn>())(
164 std::declval<const double *>(), std::declval<int>()))>
::value,
166 GradFunctor(
const PtrObj &
p, MemFn memFn, DerivMemFn gradFn,
unsigned int dim)
168 fFunc{std::bind(memFn,
p, std::placeholders::_1)},
169 fDerivFunc{std::bind(gradFn,
p, std::placeholders::_1, std::placeholders::
_2)}
175 class PtrObj,
typename MemFn,
typename GradMemFn,
176 std::enable_if_t<std::is_void<
decltype((std::declval<std::remove_pointer_t<PtrObj>>().*std::declval<GradMemFn>())(
177 std::declval<const double *>(), std::declval<double *>()))>
::value,
179 GradFunctor(
const PtrObj &
p, MemFn memFn, GradMemFn gradFn,
unsigned int dim)
181 fFunc{std::bind(memFn,
p, std::placeholders::_1)},
182 fGradFunc{std::bind(gradFn,
p, std::placeholders::_1, std::placeholders::
_2)}
190 std::function<
double(
double const *,
unsigned int)>
const&
g,
unsigned int dim)
204 GradFunctor(std::function<
double(
double const *)>
const&
f,
unsigned int dim,
205 std::function<
void(
double const *,
double *)>
const&
g)
213 unsigned int NDim()
const override {
return fDim; }
227 inline double DoEval (
const double *
x)
const override {
231 inline double DoDerivative (
const double *
x,
unsigned int icoord )
const override {
237 std::vector<double> gradBuffer(
fDim);
238 std::fill(gradBuffer.begin(), gradBuffer.end(), 0.0);
240 return gradBuffer[icoord];
278 template <
typename Func>
286 template <
class PtrObj,
typename MemFn,
typename GradMemFn>
288 :
fFunc{std::bind(memFn,
p, std::placeholders::_1)},
fDerivFunc{std::bind(gradFn,
p, std::placeholders::_1)}
295 GradFunctor1D(std::function<
double(
double)>
const&
f, std::function<
double(
double)>
const&
g)
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Functor1D class for one-dimensional functions.
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).
Documentation for class Functor class.
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 class for one-dimensional gradient functions.
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.
GradFunctor class for Multidimensional gradient functions.
void Gradient(const double *x, double *g) const override
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
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
std::function< double(const double *)> fFunc
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
virtual void Gradient(const T *x, T *grad) const
Evaluate all the vector of function derivatives (gradient) at a point x.
T Derivative(const T *x, unsigned int icoord=0) const
Return the partial derivative with respect to the passed coordinate.
Interface (abstract class) for one-dimensional functions providing a gradient calculation.
double Derivative(double x) const
Return the derivative of the function at a point x Use the private method DoDerivative.
Namespace for new Math classes and functions.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.