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