1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-11-10 00:45:36 +00:00

DoubleFunction: memory fixes

This commit is contained in:
Antonin Portelli 2015-02-26 18:50:56 +00:00
parent 465499626b
commit d93f75dac6
2 changed files with 20 additions and 11 deletions

View File

@ -109,10 +109,21 @@ DoubleFunction DoubleFunction::bind(const Index argIndex, const double val)
auto func = [copy, buf, argIndex, val](const double *arg)
{
ConstMap<DVec> argMap(arg, buf->size());
*buf = argMap;
(*buf)(argIndex) = val;
FOR_VEC(*buf, i)
{
if (i < argIndex)
{
(*buf)(i) = arg[i];
}
else if (i == argIndex)
{
(*buf)(i) = val;
}
else
{
(*buf)(i) = arg[i - 1];
}
}
return copy(*buf);
};
@ -125,12 +136,10 @@ DoubleFunction DoubleFunction::bind(const Index argIndex, const double val)
// arithmetic operators ////////////////////////////////////////////////////////
DoubleFunction DoubleFunction::operator-(void) const
{
DoubleFunction resFunc;
DoubleFunction copy(*this), resFunc;
auto res = [this](const double *arg){return -(*this)(arg);};
resFunc.setFunction(res, getNArg());
return resFunc;
return DoubleFunction([copy](const double *arg){return -copy(arg);},
getNArg());
}
#define MAKE_SELF_FUNC_OP(op)\
@ -138,7 +147,7 @@ DoubleFunction & DoubleFunction::operator op##=(const DoubleFunction &f)\
{\
DoubleFunction copy(*this);\
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());\
return *this;\
}\

View File

@ -143,7 +143,7 @@ inline DoubleFunction operator-(const double lhs, DoubleFunction rhs)
// special case for scalar/function
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());