1

according to one of the answers to this question:

When should I be using `sparse`?

you shouldn't really bother with a sparse matrix when you have more than 25% of the matrix as non-zeros

but my question is; is there a rule of thumb for what size a matrix should be before making it sparse? Is there much of an advantage to using a sparse matrix if it is only 100x100, even if there are only 5-10% non-zero entries?

what is a good threshold for matrix dimensions where it becomes a good idea to use sparse matrices?

EDIT:
just for context, i am looking at having a 500x500 matrix, with about 10000 entries, and i would like to know if i should use a sparse matrix or not. But i am also interested if there is a general rule of thumb that i should use..

Community
  • 1
  • 1
guskenny83
  • 1,321
  • 14
  • 27
  • 4
    it will probably depend what calculations you want to do with that matrices, as some functions are optimized for sparse and other not. – Robert Seifert Oct 29 '15 at 07:11
  • okay, so if i am finding myself having to use `full()` sometimes, then probably not worth using sparse? – guskenny83 Oct 29 '15 at 07:13
  • 1
    I would say that 500x500 is probably too small to be worth bothering with sparse, especially if not all the operations you want to use are supported for sparse - but the profiler will give you the best guidance. – Edric Oct 29 '15 at 08:21
  • One advantage with sparse is that in case the matrix itself really is sparse, this will allow you to do operations which may not be permitted by a non sparse matrix. In case the matrix is not really sparse you will instead end up doing more damage than before since each element in sparse consumes about 3 times as much memory. If you do a lot of operations optimized for a sparse matrix and then convert it to full I would guess that you will see a gain in perfromance anyway. Just be aware that the rvalue is most likely a double in case you create a matrix as `sparse([1,2,3;4,5,6;7,8,9]);` – patrik Oct 29 '15 at 13:05
  • My rule of thumb: If it takes a lot of memory (relative to my max RAM) and has few nnz, then sparse. If I can deal with it as non-sparse, then I dont bother – Ander Biguri Oct 29 '15 at 15:45
  • Sorry of course I mean that the rvalue is likely a full matrix (all values are doubles) – patrik Oct 30 '15 at 05:40

0 Answers0