Is it faster to operate a sparse matrix than a dense one when they have the same size?
17 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi all,
Imagine I have 2 same size matrices, both takes only the upper triangular part and sparse, their sparsity is like this:
a:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/166413/image.png)
b:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/166414/image.png)
I'm being a bit exaggerate here, in reality a would be more dense. Of course a takes much less memory than b.
If I do some operations on a and b, for example, a.*c and b.*c, where matrix c has same size, but dense, will a.*c faster than b.*c?
0 Kommentare
Antworten (2)
Star Strider
am 29 Jul. 2017
Bearbeitet: Star Strider
am 29 Jul. 2017
The best way to find out is to experiment! This is especially true if you have a specific example, such as you illustrated in your Question.
Use the timeit (link) function with two functions, one with a sparse matrix and one with a dense matrix. Compute the results you want to test with various sparse matrix and dense matrix functions and see how they compare.
EDIT —
For an extended discussion of sparse matrix computations, see the documentation on Sparse Matrix Operations (link).
0 Kommentare
Matt J
am 29 Jul. 2017
a.*c should be faster. Since a is sparser than b, there are fewer multiplication operations that need executing. The question is, how much faster. That depends on how MATLAB parallelizes the operation and could be hard to predict. If you are working on the GPU, I suspect that the performance difference may be a lot less than on the CPU.
2 Kommentare
Siehe auch
Kategorien
Mehr zu Sparse Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!