mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2024-11-10 08:55:37 +00:00
Functions: more binding utilities
This commit is contained in:
parent
57d4bfb4f8
commit
59bb3fb78c
@ -101,7 +101,8 @@ double DoubleFunction::operator()(void) const
|
||||
}
|
||||
|
||||
// bind ////////////////////////////////////////////////////////////////////////
|
||||
DoubleFunction DoubleFunction::bind(const Index argIndex, const double val)
|
||||
DoubleFunction DoubleFunction::bind(const Index argIndex,
|
||||
const double val) const
|
||||
{
|
||||
Index nArg = getNArg();
|
||||
shared_ptr<DVec> buf(new DVec(nArg));
|
||||
@ -133,6 +134,26 @@ DoubleFunction DoubleFunction::bind(const Index argIndex, const double val)
|
||||
return bindFunc;
|
||||
}
|
||||
|
||||
DoubleFunction DoubleFunction::bind(const Index argIndex,
|
||||
const DVec &x) const
|
||||
{
|
||||
Index nArg = getNArg();
|
||||
shared_ptr<DVec> buf(new DVec(nArg));
|
||||
DoubleFunction copy(*this), bindFunc;
|
||||
|
||||
auto func = [copy, buf, argIndex, x](const double *arg)
|
||||
{
|
||||
*buf = x;
|
||||
(*buf)(argIndex) = arg[0];
|
||||
|
||||
return copy(*buf);
|
||||
};
|
||||
|
||||
bindFunc.setFunction(func, 1);
|
||||
|
||||
return bindFunc;
|
||||
}
|
||||
|
||||
// arithmetic operators ////////////////////////////////////////////////////////
|
||||
DoubleFunction DoubleFunction::operator-(void) const
|
||||
{
|
||||
@ -222,3 +243,29 @@ DSample DoubleFunctionSample::operator()(const vector<double> &arg) const
|
||||
return (*this)(arg.data());
|
||||
}
|
||||
|
||||
// bind ////////////////////////////////////////////////////////////////////////
|
||||
DoubleFunctionSample DoubleFunctionSample::bind(const Index argIndex,
|
||||
const double val) const
|
||||
{
|
||||
DoubleFunctionSample bindFunc(size());
|
||||
|
||||
FOR_STAT_ARRAY(bindFunc, s)
|
||||
{
|
||||
bindFunc[s] = (*this)[s].bind(argIndex, val);
|
||||
}
|
||||
|
||||
return bindFunc;
|
||||
}
|
||||
|
||||
DoubleFunctionSample DoubleFunctionSample::bind(const Index argIndex,
|
||||
const DVec &x) const
|
||||
{
|
||||
DoubleFunctionSample bindFunc(size());
|
||||
|
||||
FOR_STAT_ARRAY(bindFunc, s)
|
||||
{
|
||||
bindFunc[s] = (*this)[s].bind(argIndex, x);
|
||||
}
|
||||
|
||||
return bindFunc;
|
||||
}
|
||||
|
@ -54,7 +54,8 @@ public:
|
||||
template <typename... Ts>
|
||||
double operator()(const double arg0, const Ts... args) const;
|
||||
// bind
|
||||
DoubleFunction bind(const Index argIndex, const double val);
|
||||
DoubleFunction bind(const Index argIndex, const double val) const;
|
||||
DoubleFunction bind(const Index argIndex, const DVec &x) const;
|
||||
// arithmetic operators
|
||||
DoubleFunction operator-(void) const;
|
||||
DoubleFunction & operator+=(const DoubleFunction &f);
|
||||
@ -170,13 +171,16 @@ public:
|
||||
DSample operator()(const std::vector<double> &arg) const;
|
||||
template <typename... Ts>
|
||||
DSample operator()(const double arg0, const Ts... args) const;
|
||||
// bind
|
||||
DoubleFunctionSample bind(const Index argIndex, const double val) const;
|
||||
DoubleFunctionSample bind(const Index argIndex, const DVec &x) const ;
|
||||
};
|
||||
|
||||
template <typename... Ts>
|
||||
DSample DoubleFunctionSample::operator()(const double arg0,
|
||||
const Ts... args) const
|
||||
{
|
||||
const double arg[] = {arg0, args...};
|
||||
const double arg[] = {arg0, static_cast<double>(args)...};
|
||||
|
||||
return (*this)(arg);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user