Eigen::SparseMatrix only allocated on heap, EIGEN_NO_MALLOC results in assertion failure
Describe the feature you would like to be implemented.
Currently, setting a SparseMatrix from a triplet list when using the EIGEN_NO_MALLOC directive results in an assertion failure (Assertion failed: false && "heap allocation is forbidden (EIGEN_NO_MALLOC is defined)", ) Example:
Eigen::SparseMatrix<double> sm1(100,100);
sm1.reserve(1000); // Number of nonzero elements
sm1.setFromTriplets(triplets.begin(), triplets.end()); // This results in an assertion failure
Sometimes, dynamic heap allocation is not allowed in some safety critical applications. The Eigen::Matrix allows to set a maximum size beforehand, and the matrix is then allocated on the stack (doesn't have to be, but that is how it is done today). It would be great to similarly allow to define an Eigen::SparseMatrix(rows, cols, nnz) that already allocates a maximum size for nnZ non-zero elements, so that it does not collide with the EIGEN_NO_MALLOC macro, and does not increase its size on the heap dynamically, once it is created.
Would such a feature be useful for other users? Why?
Other users that need the EIGEN_NO_MALLOC macro can also use SparseMatrix.
Any hints on how to implement the requested feature?
Add another constructor similar to Eigen::Matrix with maxRowsCompileTime and maxColsCompileTime, only with maxNNZCompileTime elements.