Skip to content
Snippets Groups Projects
Commit 75ae4de0 authored by Christoph Lehmann's avatar Christoph Lehmann Committed by Dmitri Naumov
Browse files

[MaL] pass Eigen::Map's by reference

parent ac3bab86
No related branches found
No related tags found
No related merge requests found
......@@ -44,7 +44,11 @@ struct FunctionHandlesImpl : FunctionHandles
bool call(const double t, const double* const y,
double* const ydot) override
{
if (f) return f(t, MappedConstVector<N>{y}, MappedVector<N>{ydot});
if (f)
{
MappedVector<N> ydot_mapped{ydot};
return f(t, MappedConstVector<N>{y}, ydot_mapped);
}
return false;
}
......@@ -52,10 +56,13 @@ struct FunctionHandlesImpl : FunctionHandles
double* const jac) override
{
if (df)
{
MappedMatrix<N, N> jac_mapped{jac};
return df(t,
MappedConstVector<N>{y},
MappedConstVector<N>{ydot},
MappedMatrix<N, N>{jac});
jac_mapped);
}
return false;
}
......
......@@ -30,13 +30,13 @@ using MappedConstVector = MappedConstMatrix<N, 1>;
template <unsigned N>
using Function = std::function<bool(
const double t, MappedConstVector<N> const y, MappedVector<N> ydot)>;
const double t, MappedConstVector<N> const& y, MappedVector<N>& ydot)>;
template <unsigned N>
using JacobianFunction = std::function<bool(const double t,
MappedConstVector<N> const y,
MappedConstVector<N> ydot,
MappedMatrix<N, N> jac)>;
MappedConstVector<N> const& y,
MappedConstVector<N> const& ydot,
MappedMatrix<N, N>& jac)>;
} // namespace MathLib
......
......@@ -16,8 +16,8 @@ const double abs_tol = 1e-8;
const double rel_tol = 1e-8;
bool f(const double,
MathLib::MappedConstVector<1> const y,
MathLib::MappedVector<1> ydot)
MathLib::MappedConstVector<1> const& y,
MathLib::MappedVector<1>& ydot)
{
if (y[0] <= 0.0) return false;
......@@ -26,9 +26,9 @@ bool f(const double,
}
bool df(const double /*t*/,
MathLib::MappedConstVector<1> const y,
MathLib::MappedConstVector<1> /*ydot*/,
MathLib::MappedMatrix<1, 1> jac)
MathLib::MappedConstVector<1> const& y,
MathLib::MappedConstVector<1> const& /*ydot*/,
MathLib::MappedMatrix<1, 1>& jac)
{
if (y[0] <= 0.0) return false;
......@@ -42,8 +42,8 @@ struct ExtraData
};
bool f_extra(const double,
MathLib::MappedConstVector<1> const y,
MathLib::MappedVector<1> ydot,
MathLib::MappedConstVector<1> const& y,
MathLib::MappedVector<1>& ydot,
ExtraData& data)
{
if (y[0] <= 0.0) return false;
......@@ -153,8 +153,8 @@ TEST(MathLibCVodeTest, ExponentialExtraData)
ExtraData data;
auto f_lambda = [&](double t,
MathLib::MappedConstVector<1> const y,
MathLib::MappedVector<1> ydot)
MathLib::MappedConstVector<1> const& y,
MathLib::MappedVector<1>& ydot)
{
return f_extra(t, y, ydot, data);
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment