- changed status to wontfix
Sparse matrix construction is slow
Issue #252
closed
Hi, I am using blaze to create a sparse matrix from a set of tuples in a file. I follow Wiki to append elements row by row (reserve
, append
,finalize
) but it is very slow. Is there anything wrong with my sparse matrix construction?
The code is here: https://bitbucket.org/clin99/image_reader/src/master/
Thanks!
Comments (3)
-
-
reporter Hi Klaus,
I have tried your solution and now the construction is fast! Thanks for your answering!
Best regards,
Chun-Xun
-
reporter - changed status to closed
- Log in to comment
Hi Chun!
The problem is the call to
.reserve()
within thefor
loop. Every call to.reserve()
causes a memory allocation and with that an additional copy operation for all the data that has already been added to the matrix. You can significantly speed up the setup of the sparse matrix if you use a different constructor:This will configure the
CompressedMatrix
in a single step. There is exactly one memory allocation and no addition copy operations. I hope this helps,Best regards,
Klaus!