[eigen] Valid use case for creating a SparseMatrix?

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


I know that the Sparse API isn't stable yet. I'm using it though. At the
moment I'm filling a sparse matrix and I stumbled over a little problem
and I'd like to know what's your view on the matter.
When filling the matrix I do not know in advance how many cols/rows it
contains. I know that they are sorted such that I can use the
SparseMatrix class. Interestingly for the SparseVector I can fill it
without knowing the number of values and without specifying the number
of cols, rows respectively. Technically SparseMatrix could offer the
same. I know this might be rather rare use case. In my case I need to
get the data from a text file into Eigen but the file format doesn't
give the dimensions of the matrix. So I first parse into std::vector to
determine the maximal column index and then convert from there to a
SparseMatrix in Eigen. The same holds for the number of rows.
Usually a sparse matrix is seen as a special matrix and for a matrix you
have to specify the dimensions when declaring it but seen from a data
structural point of view (in this case assuming the compress row/col
storage format) you don't have to specify the dimensions.
SparseMatrix<double> matrix; // I do not know the dimensions here
// filling in sorted color major here
// this will fix the maximal indices for rows/cols
matrix.finalize(); // sets the dimensions appropriately


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/