mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2025-04-10 19:20:44 +01:00
DoubleFunction: memory fixes
This commit is contained in:
parent
465499626b
commit
d93f75dac6
@ -109,10 +109,21 @@ DoubleFunction DoubleFunction::bind(const Index argIndex, const double val)
|
|||||||
|
|
||||||
auto func = [copy, buf, argIndex, val](const double *arg)
|
auto func = [copy, buf, argIndex, val](const double *arg)
|
||||||
{
|
{
|
||||||
ConstMap<DVec> argMap(arg, buf->size());
|
FOR_VEC(*buf, i)
|
||||||
|
{
|
||||||
*buf = argMap;
|
if (i < argIndex)
|
||||||
(*buf)(argIndex) = val;
|
{
|
||||||
|
(*buf)(i) = arg[i];
|
||||||
|
}
|
||||||
|
else if (i == argIndex)
|
||||||
|
{
|
||||||
|
(*buf)(i) = val;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
(*buf)(i) = arg[i - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return copy(*buf);
|
return copy(*buf);
|
||||||
};
|
};
|
||||||
@ -125,12 +136,10 @@ DoubleFunction DoubleFunction::bind(const Index argIndex, const double val)
|
|||||||
// arithmetic operators ////////////////////////////////////////////////////////
|
// arithmetic operators ////////////////////////////////////////////////////////
|
||||||
DoubleFunction DoubleFunction::operator-(void) const
|
DoubleFunction DoubleFunction::operator-(void) const
|
||||||
{
|
{
|
||||||
DoubleFunction resFunc;
|
DoubleFunction copy(*this), resFunc;
|
||||||
|
|
||||||
auto res = [this](const double *arg){return -(*this)(arg);};
|
return DoubleFunction([copy](const double *arg){return -copy(arg);},
|
||||||
resFunc.setFunction(res, getNArg());
|
getNArg());
|
||||||
|
|
||||||
return resFunc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAKE_SELF_FUNC_OP(op)\
|
#define MAKE_SELF_FUNC_OP(op)\
|
||||||
@ -138,7 +147,7 @@ DoubleFunction & DoubleFunction::operator op##=(const DoubleFunction &f)\
|
|||||||
{\
|
{\
|
||||||
DoubleFunction copy(*this);\
|
DoubleFunction copy(*this);\
|
||||||
checkSize(f.getNArg());\
|
checkSize(f.getNArg());\
|
||||||
auto res = [&f, copy](const double *arg){return copy(arg) op f(arg);};\
|
auto res = [f, copy](const double *arg){return copy(arg) op f(arg);};\
|
||||||
setFunction(res, getNArg());\
|
setFunction(res, getNArg());\
|
||||||
return *this;\
|
return *this;\
|
||||||
}\
|
}\
|
||||||
|
@ -143,7 +143,7 @@ inline DoubleFunction operator-(const double lhs, DoubleFunction rhs)
|
|||||||
// special case for scalar/function
|
// special case for scalar/function
|
||||||
inline DoubleFunction operator/(const double lhs, DoubleFunction rhs)
|
inline DoubleFunction operator/(const double lhs, DoubleFunction rhs)
|
||||||
{
|
{
|
||||||
auto res = [lhs, &rhs](const double *arg){return lhs/rhs(arg);};
|
auto res = [lhs, rhs](const double *arg){return lhs/rhs(arg);};
|
||||||
|
|
||||||
rhs.setFunction(res, rhs.getNArg());
|
rhs.setFunction(res, rhs.getNArg());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user