I'm using Eigen with big matrices and I'm thinking about ways to optimize my code, focusing on reducing dynamic memory allocation.
I'm trying to multiply two matrices. Those matrices change a little bit every now and then, but their sizes stay the same.
I'd like to see the output of the multiplication going to a predefined matrix (that would have memory already allocated for it).
So here's an example of what I'm doing:
Eigen::MatrixXd left, right,result;
// ...
result = left * right;
// ... left and right values change a little
result = left * right;
And I'm looking for a solution that would be like that:
void Multiply(
Eigen::MatrixXd const& left,
Eigen::MatrixXd const& right,
Eigen::MatrixXd& result);
void Example()
{
Eigen::MatrixXd left, right, result;
// ...
Multiply(left, right, result);
// ...
Multiply(left, right, result);
}
The aim is basically to reuse the result matrix memory because in theory it should not change dimension. I was thinking about using operator*= but I kind of realize that it still needs an intermediate matrix to do the calculation.
result=left*rightactually reallocates when result already has the right size? - Marc Glisse