[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: fastest way to test a logical vector
From: |
Jaroslav Hajek |
Subject: |
Re: fastest way to test a logical vector |
Date: |
Wed, 20 Jan 2010 12:58:53 +0100 |
On Wed, Jan 20, 2010 at 12:42 PM, Dupuis <address@hidden> wrote:
>
> Hello,
>
> I'm analysing a signal where outliers are not uncommon. So the main loop
> contains a number of test like
>
> sum(x(indi-(1:4)) >= 0) >= 2 && sum(x(indi+(1:4)) <= 2) >= 2,
>
> I tried to optimise x and indi as int16, so the types are
> x(indi-(1:4)) vector of int16
> x(indi-(1:4)) >= 0 vector of logical
> sum(x(indi-(1:4)) >= 0) double
>
> Is there a way to avoid, in the last operation, the logical -> double
> conversion ?
There is no logical -> double conversion involved here. In 3.2.x, sums
of logical arrays are done by simply counting true elements.
> any() doesn't fit the requirement, as it test for one value. I
> thinked about
> sort(x(indi-(1:4)) >= 0))(3) == 1
> But this implies to call sort at each test. Does someone see a faster
> solution ? I'm working with octave3.2
>
> Regards
>
> Pascal
>
Btw, note that in an expression like
sum(x(indi-(1:4)) >= 0) >= 2 && sum(x(indi+(1:4)) <= 2) >= 2,
the interpreter overhead will likely play the major role. If you can
present a more complete code that you wish to optimize, someone may
give you a better hint.
--
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz
Re: fastest way to test a logical vector,
Jaroslav Hajek <=