Hello devs,
There's a nice little feature that just got implemented in Eigen, and should
be out for eigen3 RC1 that might be useful to those of you doing
matrix/vector operations on contexts where no allocations can be made. Small
example:
#define EIGEN_RUNTIME_NO_MALLOC // Define this symbol to enable runtime
tests for allocations
#include <Eigen/Dense>
int main(int argc, char** argv)
{
// It's OK to allocate here
const int rows = 10;
const int cols = 15;
Eigen::MatrixXd A = Eigen::MatrixXd::Random(rows, cols);
Eigen::JacobiSVD<MatrixXd> svd(rows, cols);
// It's NOT OK to allocate here
// An assertion will be triggered if an Eigen-related heap allocation
takes place
Eigen::internal::set_is_malloc_allowed(false);
svd.compute(A);
Eigen::internal::set_is_malloc_allowed(true);
// It's OK to allocate again
}
Many thanks to Benoit Jacob for implementing this and enabling the inclusion
of no-heap-allocation tests in Eigen's test suite.
Happy coding,
Adolfo.