It seems to me that indexing sparse matrices, like
m[i,:] is way too slow, even if one is retrieving columns.
In fact, it seems to take time proportional to the dimension
of the matrix, rather than to the number of non-zeros in the column.

For example, consider the following timings:

n = 10000;
e = speye(n);
x = 0;
tic();
for i = 1:n; x = x + sum(find(e[:,i])); end
toc()

elapsed time: 1.388211586 seconds

n = 20000;
e = speye(n);
x = 0;
tic();
for i = 1:n; x = x + sum(find(e[:,i])); end
toc()

elapsed time: 6.076672088 seconds

n = 40000;
e = speye(n);
x = 0;
tic();
for i = 1:n; x = x + sum(find(e[:,i])); end
toc()

elapsed time: 22.653318711 seconds

Thanks,
  Dan Spielman

Reply via email to