0
votes

It seems that (*=) can't be operated on row view of a ColMajor sparsematrix in Eigen 3.2.10 as follows

    SparseMatrix<double, ColMajor> spmat(3, 3);
    spmat.coeffRef(0, 0) = 1.1;
    spmat.coeffRef(1, 1) = 2.2;
    spmat.coeffRef(2, 2) = 3.3;
    spmat.row(2) *= 2.0;   // compile failed!

where the spmat.row(2) in a SparseMatrix<double, ColMajor> type is read-only type, not the reference type. In the changelog of Eigen 3.2.10, it says ' fix support for row (resp. column) of a column-major (resp. row-major) sparse matrix', but I think the operation *= in row view of a ColMajor sparmatrix is necessary, so does anyone have a good solution to this problem?

1
See this post. Basically, (at least as of Eigen 3.2.*) the answer is no, as it's not efficient.Avi Ginsburg
thanks for quick reply, I checked that post and Eigen document, you are right, but before Eigen 3.2.10, the spmat.row(n) can be modified, maybe it is a bug that make the code inefficient as you said.Steve Shi
Taking the row of a compressed column storage matrix is inherently inefficient as looping over its coefficients cost O(n * log(m)) with n the number of columns and m the average number of non-zeros per column. With sparse matrices, it is expected that n>20000 and m<100. In contrast, operating on a column cost O(m). So if you need to work on rows, better copy it to a row-major format first (cost is O(m*n), so almost as costly as processing a single row).ggael

1 Answers

0
votes

If you need to stay on the 3.2 branch, you can workaround like this (source):

spmat.middleRows(2,0) *= 2.0;

Better yet, update to Eigen 3.3, or consider using a row-major matrix, when doing a lot of row-operations.