On 1-Mar-2010, David Bateman wrote:
| sub-dividing your example a bit with the example
|
| octave:1> n=1e5;d=0.01;y=floor(10*sprand(n,1,d));tic; x1 = y(1:n-1);
| toc; tic; x2 = y(2:n); toc; tic; match = (x1 == x2);toc; tic; idx=
| find(match); toc; tic; y(idx) = [];toc
| Elapsed time is 1.09358 seconds.
| Elapsed time is 1.06628 seconds.
| Elapsed time is 0.003949 seconds.
| Elapsed time is 0.011372 seconds.
| Elapsed time is 0.291622 seconds.
|
| it seems that is that the "Sparse<T>::index (const idx_vector&, int)
| const" method is slow but the maybe_delete_elements method is a bit slow
| as well. Note that Jaroslav accelerated the Array<T>::index methods in
| 3.2.x by reworking the idx_vector class to do the indexing. The
| Sparse<T> class didn't get the same treatment.
|
| I suppose we can just special case the contiguous index vector of a
| sparse vector case in the sparse index and maybe_delete_elements method
| to get this to be faster and the attached patch does this with the result
|
| octave:1> n=1e5;d=0.01;y=floor(10*sprand(n,1,d));tic; x1 = y(1:n-1);
| toc; tic; x2 = y(2:n); toc; tic; match = (x1 == x2);toc; tic; idx=
| find(match); toc; tic; y(idx) = [];toc
| Elapsed time is 0.00018991 seconds.
| Elapsed time is 0.00011495 seconds.
| Elapsed time is 0.0079711 seconds.
| Elapsed time is 0.023946 seconds.
| Elapsed time is 0.039251 seconds.
|
| Is this improvement sufficient to make your change to the unique
| function obsolete? If it does I'll work it up as a changeset
Yes, this brings the performance of the unique example much closer to
the full case, so with it, I would remove my previous change to
unique.m.
It looks like your patch is relative to a version of Sparse.cc from
before the great untabifying. I'm attaching a version relative to the
current sources, which should apply cleanly to the current sources.