Registered Member
|
Hi,
I'm working on panel-clustering methods where the problem's near field can be stored in large sparse matrices. Unfortunately, those matrices can still require about 1500 non-zero entries per row, which significantly degrades the performance of DynamicSparseMatrix (as stated in the headers, too). When I tried to use the SparseMatrix class, performance seemed to be even worse (but maybe I just used it in an incorrect way). Could you advise on how I could improve the performance of DynamicSparseMatrix or use SparseMatrix with optimal performance instead? If this helps, I am able precompute the sparsity pattern in order to achieve a specific order to fill the matrix entries. Best and thanks in advance, Daniel |
Moderator
|
The best is to use SparseMatrix (because DynamicSparseMatrix is "unsupported"). The simplest way to get good perf. is to follow the recommandation of the tutorial that is to use a std::vector<Triplet<..> > and let SparseMatrix::setFromTriplets does the job. Otherwise, you could compute the exact number of non-zeros per inner-vector, store them into a std::vector<int> or Eigen::VectorXi, and call mat.resize(this_vector); to preallocate room for each inner vector. Then calling mat.insert(i,j) with increasing inner indices per outer-vector should be optimally fast.
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]