Inefficient handling of sparse matrices by the norm function
Nir Krakauer
niryk at berkeley.edu
Wed Dec 5 16:34:21 CST 2007
Dear all,
Through trying the matrix exponentiation package Expokit ( http://
www.maths.uq.edu.au/expokit/ ) with Octave, I noticed that the Octave
norm function is very inefficient for sparse matrices:
octave-2.9.15:1> A = spdiag(rand(4E4, 1)); %A is large but very sparse
octave-2.9.15:2> tic; anorm = norm(A, 'inf'); toc
Elapsed time is 29.915062 seconds.
octave-2.9.15:3> tic; anorm2 = max(max(abs(A))); toc %does the same
thing
Elapsed time is 0.056305 seconds.
Apparently, the implementation searches for the maximum matrix value
among the zero values of A, not just the nonzero values, and so takes
much longer than it needs to. By contrast, Matlab does this fast
(version 7.4.0 / 2007a):
>> A = spdiags(rand(4E4, 1), 0, 4E4, 4E4); %(no spdiag command in
Matlab)
>> tic; anorm = norm(A, 'inf'); toc
Elapsed time is 0.006415 seconds.
>> tic; anorm2 = max(max(abs(A))); toc
Elapsed time is 0.036588 seconds.
The workaround of using max(max(abs(A))) is fine for my application,
but it would be nice to have norm work efficiently also.
I'm using Octave version 2.9.15 on an Intel MacBook (10.4).
Best,
Nir
________________________
Nir Y. Krakauer
NOAA Climate and Global Change Postdoctoral Fellow
Department of Earth and Planetary Science
University of California - Berkeley
Berkeley, CA 94720-4767
niryk at berkeley.edu
http://www.atmos.berkeley.edu/~niryk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www.cae.wisc.edu/pipermail/bug-octave/attachments/20071205/0e029e1e/attachment-0001.html
More information about the Bug-octave
mailing list