Registered Member
|
Bellow is the program and the problem:
typedef Eigen::SparseMatrix<double> SparseMatrix; typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> DenseMatrix; SparseMatrix X; DenseMatrix C; // At some point in code I need to calculate the following for some integers i from a given set: C * X.col(i) //At the same time, I need to calculate the following for the same integers i. Integer index is fixed for all integers i: C.row(index) += X.col(i).transpose(); // In other words, the first time we multiply a dense matrix with a given sparse columns, // while the second time, we simply sum the same given sparse columns into a single dense vector. Why is summing (in my experiments) 4 times slower than multiplication? Should not it be faster? The size of matrices in my experiments are: X : cols = 2.2 Million X : rows = 1300 C : cols = 1300 |
Moderator
|
yes, this is because dense += sparse is currently treated as "dense = anotherdense + sparse" and so this is O(C.cols()) operation while it should be a O(X.col(i).nonZeros()) op.
|
Registered Member
|
Great, thanks a lot.
What would be then the "fastest" way to sum a given set of sparse vectors into a single dense vector? |
Moderator
|
in the meantime:
for(SparseMatrixType::InnerIterator it(X,i); it; ++it) C(i,it.index()) += it.value(); |
Registered users: Baidu [Spider], Bing [Bot], Google [Bot], Yahoo [Bot]