octave-bug-tracker
[Top][All Lists]
Advanced

[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(:);
  else
    v = A(find (A));
    v = v(:);
  endif


I checked this in on the development branch of Octave
(http://hg.savannah.gnu.org/hgweb/octave/rev/ff830f8e61ac).


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?53605>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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