![]() Registered Member ![]()
|
Hi guys,
I have done quite some digging in the docs and here in the forum, but I can't seem to find an elegant solution to this seemingly simple operation: At the beginning of my program, I have a big m*m integer matrix M_dense, initialized entirely to 0 (m > 5.000). In the end, this matrix is going to be really dense, there should be not a single 0. This is how it is filled: Repeat thousands of times: 1. Compute a _sparse_ m*n matrix M_sparse (dont ask how; n can range from 10 to 10000) 2. Multply this M_sparse by its transposed self => new m*m matrix 3. Add this new m*m matrix to the m*m matrix M_dense (above) I want to do steps 2-3 in Eigen, but I can't seem to find an elegant (memory, cpu-friendly) way to do it. As Matrix types, I use for M_dense:
and for M_sparse:
(RowMajor, because the data comes RowMajor from a C program) I initialize the sparse matrix via a list of triplets (see docs), and M_dense like this:
(where pointer_to_int_array is a pointer to an int array with m*m elements.) Now, ideally, I would like to do steps 2 and 3 like this:
But this line doesn't work and results in a huge error message (traceback) with these last errors from the compiler:
Then I introduce an intermediate result (what I actually wanted to avoid), but now the operator is undefined:
error:
What am I doing wrong here? What can I do to avoid a) an intermediate sparse matrix that first stores the result of the multiplication and b) an extra loop over this sparse matrix to add the values to the dense matrix? Thanks a lot for your help! Best new2you P.S: Here is the complete code (latter version):
|
![]() Moderator ![]()
|
dense += sparse is not supported yet, you can workaround with dense = dense + sparse though this will be a n^2 op.
|
![]() Registered Member ![]()
|
I have a similar question. I have sparse matrix and I need to multiply it by itself and assign to a dense matrix. If I try to directly assign the product to a dense matrix, it fails at compile time:
If I assign to a temporary, however, the code compiles fine:
Can I avoid this temporary? Thank you! |
![]() Registered Member ![]()
|
This doesn't work for me with gcc-4.2.1 on Mac 10.7.5 with Eigen 3.1.2:
$ g++ -IEigen -c t2.cpp -o t2.o t2.cpp: In function ‘void selfMultiplyMatrix(int*, int, int*, int, int)’: t2.cpp:30: error: no match for ‘operator+’ in ‘M_dense + M_sparse_squared’ Any ideas? |
Registered users: Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]