octave-maintainers
[Top][All Lists]
Advanced

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

Re: Speed up 'unique'


From: Jaroslav Hajek
Subject: Re: Speed up 'unique'
Date: Thu, 18 Dec 2008 12:09:41 +0100

On Wed, Dec 17, 2008 at 11:52 AM, Daniel J Sebald
<address@hidden> wrote:
> Attached is a patch that tweaks unique.m to cut the time of the
> following test by 4:
>
> function testfunc3(m, varargin)
>  x = [[1:20] [20:-1:1]];
>  tstart = cputime();
>  for i=1:5000
>   [y i j] = unique(x);
>  end
>  cputime() - tstart
> end
>
> The reason for the improvement is that all the testing for the options
> is avoided if no options are present.  (I.e., avoids three calls to
> 'strmatch' and a couple conditionals.)  Also, 'prepad' really isn't a
> necessary call, as I see it.
>
> If one looks closely at the handling of options, I added a recursive
> call to make sure the options are unique.  Otherwise, something like
> this fails:
>
> unique([1:10], 'first', 'first')
>
> The recursion looks funny, but because of the added check on the number
> of arguments, it is not an indefinite loop.
>
> Dan
>

Also, when making patches by means other than mercurial, please change
the header to include full path in the source tree, and distinguish
the revision by a leading path component, like this:

--- a/scripts/set/unique.m      2008-12-17 03:08:02.000000000 -0600
+++ b/scripts/set/unique.m      2008-12-17 04:45:08.590020461 -0600

That way, the patch can be directly imported by Mercurial.



-- 
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz


reply via email to

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