Registered Member
|
Hello,
I'm interested in finding out the sparsity fraction of a MatrixXd without having to write helper function loops etc i.e. count the zeros and then get: sparsity fraction = zeroCount/M*N Is there some provision in Eigen for this use-case somewhere in whatever form? I need it to automatically switch between dense and sparse solvers. TIA, Best regards, Giovanni |
Moderator
|
That's easy: double(mat.nonZeros())/double(mat.size())
|
Moderator
|
hm wait, the above works for a sparse matrix, so for a MatrixXd: double((mat.array()!=0).count()) / double(mat.size())
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]