Registered Member
|
Hi,
I have a simple sparse matrix class build out of 3 vectors Val - non zero values. Col - the column of each non zero value R_ptr - row pointer that tells you when to go to the next row All stored as std::vector So basically standard CRS format to store sparse matrix I can't figure out how to map in to eigen sparse matrix without having to loop through the values (which is very slow Any help please? |
Moderator
|
See: http://eigen.tuxfamily.org/dox-devel/gr ... tml#title3 (last line). In short:
Map<SparseMatrix<double,RowMajor> > mat(rows,cols,nnz,R_ptr,Col,Val); |
Registered Member
|
Thank you ggael!
However, I am still struggling making a simple task work. Let say I just want to enter the complex diagonal matrix (with real entries at the moment) that i have built separately in CRS format A = [ 1 0 0 ] [ 0 2 0 ] [ 0 0 3 ] The following code doesn't work for me :/ Code: #include <vector> #include <complex> #include <Eigen/Sparse> std::vector<std::complex<double> > values({ 1,2,3 }); std::vector<int> columns({ 0,1,2 }); std::vector<int> row_pointer({ 0,1,2,3 }); Eigen::Map<Eigen::SparseMatrix<std::complex<double>, Eigen::RowMajor> > mat(3, 3, 3, row_pointer, columns, values); code end. I have tried several formatting similar to that. can't make it to work. Have any idea why ? Thanks again! |
Moderator
|
You need to pass pointers, so row_pointer .data(), columns.data(), etc.
|
Registered Member
|
Yea, I saw that in the Eigen manual. The problem that is still doesn't work.
Tried also to use .begin() of .front with and with out & * Nothing works It gives me this error: Error (active) no instance of constructor "Eigen::Map<PlainObjectType, MapOptions, StrideType>::Map [with PlainObjectType=Eigen::SparseMatrix<std::complex<double>, 1, int>, MapOptions=0, StrideType=Eigen::Stride<0, 0>]" matches the argument list I can't find a way to resolve it. Any clue what might cause it? Maybe need to include more libraries? |
Moderator
|
oh, you must use Eigen 3.3 for that feature. In 3.2, there is MappedSparseMatrix which is equivalent but deprecated in 3.3.
|
Registered users: Bing [Bot], Google [Bot], Sogou [Bot]