BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType > Class Template Reference

Description

template<class MultiFuncType = const ROOT::Math::IMultiGenFunction &>
class ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >

OneDimMultiFunctionAdapter class to wrap a multidimensional function in one dimensional one. Given a f(x1,x2,x3,....xn) transforms in a f( x_i) given the coordinate intex i and the vector x[] of the coordinates. It provides the possibility to copy and own the data array of the coordinates or to maintain internally a pointer to an external array for being more efficient. In this last case the user must garantee the life of the given passed pointer

Definition at line 56 of file OneDimFunctionAdapter.h.

Inheritance diagram for ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >:
[legend]
Collaboration diagram for ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >:
[legend]

Public Types

typedef IBaseFunctionOneDim BaseFunc
 

Public Member Functions

 OneDimMultiFunctionAdapter (const OneDimMultiFunctionAdapter &rhs)
 
 OneDimMultiFunctionAdapter (MultiFuncType f, const double *x, unsigned int icoord=0, const double *p=0)
 
 OneDimMultiFunctionAdapter (MultiFuncType f, unsigned int dim=1, unsigned int icoord=0, const double *p=0)
 
virtual ~OneDimMultiFunctionAdapter ()
 
virtual OneDimMultiFunctionAdapterClone () const
 
double operator() (const double *x) const
 
double operator() (double x) const
 
void SetCoord (int icoord)
 
void SetX (const double *x)
 
void SetX (double *x)
 
template<class Iterator >
void SetX (Iterator begin, Iterator end)
 

Private Member Functions

double DoEval (double x) const
 
OneDimMultiFunctionAdapteroperator= (const OneDimMultiFunctionAdapter &rhs)
 

Private Attributes

unsigned int fCoord
 
unsigned int fDim
 
MultiFuncType fFunc
 
bool fOwn
 
const double * fParams
 
double * fX
 

Member Typedef Documentation

◆ BaseFunc

Definition at line 139 of file IFunction.h.

Constructor & Destructor Documentation

◆ OneDimMultiFunctionAdapter() [1/3]

template<class MultiFuncType = const ROOT::Math::IMultiGenFunction &>
ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::OneDimMultiFunctionAdapter ( MultiFuncType  f,
const double *  x,
unsigned int  icoord = 0,
const double *  p = 0 
)
inline

Constructor from the function object , pointer to an external array of x values and coordinate we want to adapt

Definition at line 65 of file OneDimFunctionAdapter.h.

65  :
66  fFunc(f),
67  fX( const_cast<double *>(x) ), // wee need to modify x but then we restore it as before
68  fParams(p),
69  fCoord(icoord),
70  fDim(0),
71  fOwn(false)
72  {
73  assert(fX != 0);
74  }

References ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::fX.

Referenced by ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::Clone().

◆ OneDimMultiFunctionAdapter() [2/3]

template<class MultiFuncType = const ROOT::Math::IMultiGenFunction &>
ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::OneDimMultiFunctionAdapter ( MultiFuncType  f,
unsigned int  dim = 1,
unsigned int  icoord = 0,
const double *  p = 0 
)
inline

Constructor from the function object , dimension of the function and and coordinate we want to adapt. The coordinate cached vector is created inside and eventually the values must be passed later with the SetX which will copy them

Definition at line 81 of file OneDimFunctionAdapter.h.

81  :
82  fFunc(f),
83  fX(0 ),
84  fParams(p),
85  fCoord(icoord),
86  fDim(dim),
87  fOwn(true)
88  {
89  fX = new double[dim];
90  }

References ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::fX.

◆ ~OneDimMultiFunctionAdapter()

template<class MultiFuncType = const ROOT::Math::IMultiGenFunction &>
virtual ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::~OneDimMultiFunctionAdapter ( )
inlinevirtual

Destructor (no operations)

Definition at line 95 of file OneDimFunctionAdapter.h.

95 { if (fOwn && fX) delete [] fX; }

References ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::fOwn, and ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::fX.

◆ OneDimMultiFunctionAdapter() [3/3]

template<class MultiFuncType = const ROOT::Math::IMultiGenFunction &>
ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::OneDimMultiFunctionAdapter ( const OneDimMultiFunctionAdapter< MultiFuncType > &  rhs)
inline

Definition at line 142 of file OneDimFunctionAdapter.h.

142  :
143  fFunc(rhs.fFunc),
144  fParams(rhs.fParams),
145  fCoord(rhs.fCoord),
146  fDim(rhs.fDim),
147  fOwn(rhs.fOwn)
148  {
149  if (fOwn) {
150  fX = new double[fDim];
151  std::copy( rhs.fX, rhs.fX+fDim, fX);
152  }
153  else fX = rhs.fX;
154  }

References ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::fDim, ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::fOwn, and ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::fX.

Member Function Documentation

◆ Clone()

template<class MultiFuncType = const ROOT::Math::IMultiGenFunction &>
virtual OneDimMultiFunctionAdapter* ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::Clone ( ) const
inlinevirtual

◆ DoEval()

template<class MultiFuncType = const ROOT::Math::IMultiGenFunction &>
double ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::DoEval ( double  x) const
inlineprivatevirtual

evaluate function at the values x[] given in the constructor and as function of the coordinate fCoord.

Implements ROOT::Math::IBaseFunctionOneDim.

Definition at line 169 of file OneDimFunctionAdapter.h.

169  {
170  if (fOwn) {
171  fX[fCoord] = x;
173  }
174  else {
175 
176  // case vector fX represents useful values needed later
177  // need to modify fX and restore afterwards the original values
178  double xprev = fX[fCoord]; // keep original value to restore in fX
179  fX[fCoord] = x;
181  // restore original values
182  fX[fCoord] = xprev;
183  return y;
184  }
185  }
static double F(MultiFuncType f, const double *x, const double *=0)

References ROOT::Math::EvaluatorOneDim< MultiFuncType >::F(), ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::fCoord, ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::fFunc, ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::fOwn, ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::fParams, and ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::fX.

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=()

template<class MultiFuncType = const ROOT::Math::IMultiGenFunction &>
OneDimMultiFunctionAdapter& ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::operator= ( const OneDimMultiFunctionAdapter< MultiFuncType > &  rhs)
inlineprivate

Definition at line 160 of file OneDimFunctionAdapter.h.

160  {
161  if (this == &rhs) return *this;
162  assert(false);
163  }

◆ SetCoord()

template<class MultiFuncType = const ROOT::Math::IMultiGenFunction &>
void ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::SetCoord ( int  icoord)
inline

◆ SetX() [1/3]

template<class MultiFuncType = const ROOT::Math::IMultiGenFunction &>
void ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::SetX ( const double *  x)
inline

set values

Definition at line 132 of file OneDimFunctionAdapter.h.

132  {
133  if (fOwn) std::copy(x, x+fDim, fX);
134  else
135  SetX( const_cast<double *>(x) ); // wee need to modify x but then we restore it as before
136  }
void SetX(Iterator begin, Iterator end)

References ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::fDim, ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::fOwn, ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::fX, and ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::SetX().

Here is the call graph for this function:

◆ SetX() [2/3]

template<class MultiFuncType = const ROOT::Math::IMultiGenFunction &>
void ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::SetX ( double *  x)
inline

set pointer without copying the values

Definition at line 125 of file OneDimFunctionAdapter.h.

125  {
126  if (!fOwn) fX = x;
127  }

References ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::fOwn, and ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::fX.

◆ SetX() [3/3]

template<class MultiFuncType = const ROOT::Math::IMultiGenFunction &>
template<class Iterator >
void ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::SetX ( Iterator  begin,
Iterator  end 
)
inline

Set X values in case vector is own, iterator size must match previous set dimension

Definition at line 117 of file OneDimFunctionAdapter.h.

117  {
118  if (fOwn) std::copy(begin, end, fX);
119  }

References ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::fOwn, and ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::fX.

Referenced by ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::SetX().

Member Data Documentation

◆ fCoord

◆ fDim

◆ fFunc

template<class MultiFuncType = const ROOT::Math::IMultiGenFunction &>
MultiFuncType ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::fFunc
private

◆ fOwn

◆ fParams

template<class MultiFuncType = const ROOT::Math::IMultiGenFunction &>
const double* ROOT::Math::OneDimMultiFunctionAdapter< MultiFuncType >::fParams
private

◆ fX


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