Inefficient handling of sparse matrices by the norm function

David Bateman adb014 at gmail.com
Thu Dec 6 15:11:45 CST 2007


Jason Riedy wrote:
> And David Bateman writes:
>> Yes, but still pathetic.. The issue is that the sum function is
>> converting the matrix to full before doing the summation. I'm
>> working on a patch
> 
> Oof.  I thought it was because I had a zillion things running.
> 
> A quick patch might be to implement sum/spsum as a matrix-
> vector product in the sparse case:
> 
> octave:6> A = spdiag(rand(4E4, 1));
> octave:7> tic; anorm = norm(A, 'inf'); toc
> Elapsed time is 10.721107 seconds.
> octave:8> tic; anorm2 = max(sum(abs(A),2)); toc
> Elapsed time is 10.719147 seconds.
> octave:9> tic; anorm3 = max(spsum(abs(A),2)); toc
> Elapsed time is 10.686447 seconds.
> octave:10> tic; anorm4 = max(abs(A)*ones(size(A,2),1)); toc
> Elapsed time is 0.010323 seconds.
> 
> 
> Jason


Better to fix the src/data.cc{DATA_REDUCTION|NATIVE_REDUCTION} macros to
accept sparse matrices.. Even better would be to add sum/cumsum, etc
methods to the octave_value classes and use them rather than an ugly
macro, but that can wait till after 3.0 :-)

I'm testing my patch now, as a update to 2.9.18+ caused a complete
rebuild of Octave, so its a little slow..

D.


More information about the Bug-octave mailing list