[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #53605] (minor) nonzeros.m can be made twice a

From: Rik
Subject: [Octave-bug-tracker] [bug #53605] (minor) nonzeros.m can be made twice as fast, as follows:
Date: Tue, 10 Apr 2018 18:43:50 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0

Update of bug #53605 (project octave):

                  Status:                    None => Fixed                  
             Open/Closed:                    Open => Closed                 


Follow-up Comment #2:

It's a little more complicated than that.  nonzeros(), according to the
documentation, is meant for sparse matrices.  If you try it on sparse matrices
then using the third argument from find() approach is 10X faster than using
indexing.  But for full matrices, the approache you recommended is faster. 
The solution, obviously, is just to check the incoming matrix type and use the
fastest algorithm.

  if (issparse (A))
    [~, ~, v] = find (A);
    v = v(:);
    v = A(find (A));
    v = v(:);

I checked this in on the development branch of Octave


Reply to this item at:


  Message sent via/by Savannah

reply via email to

[Prev in Thread] Current Thread [Next in Thread]