help-octave
[Top][All Lists]
Advanced

[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: Thu, 21 Jan 2010 13:19:54 +0100

On Thu, Jan 21, 2010 at 11:36 AM, Dupuis <address@hidden> wrote:
>
>
> Jaroslav Hajek-2 wrote:
>>
>>
>> Yes, this is quite expectable.
>>
>>> Now my problem is that I'm implementing a kind of state machine. I can
>>> write
>>> state(2) as a function of state(1) and so on, but state(1) depends on the
>>> latest state, so direct work on vector would not work. Any idea on how to
>>> solve this ?
>>
>> This kind of problems is quite difficult to vectorize, admittedly. It
>> heavily depends on the problem at hand. In general, the "filter"
>> function can be of use (for difference equations), as well as the
>> cumulative reductions (cumsum etc).
>> For other options, see the signal package:
>> http://octave.sourceforge.net/signal/index.html
>>
>> --
>> RNDr. Jaroslav Hajek, PhD
>> computing expert & GNU Octave developer
>> Aeronautical Research and Test Institute (VZLU)
>> Prague, Czech Republic
>> url: www.highegg.matfyz.cz
>>
>>
>
> To give an order of magnitude : on around 1000 points, there are typically
> 12 events to detect. I first implemented a state machine, where each point
> was analysed inside a 'switch' clause. Now, I've vectorised all tests, and
> detect the transitions in logical states. I have for instance
> - test1 = logical vector telling if state == state1
> - test2 = logical vector of telling if state == state2
> - s1= indexes where test1 stop being true,
> - s2 = indexes where test2 start being true.
>
> Their intersection is where we have a transition from state1 to state2.
> Instead on working on the 1000 points, I have lists of around 10 transition
> indexes. The achieved speed gain is more than 10.
>
> Regards
>
> Pascal
> --

Well done. Please consider sharing your tricks here or (better) at the
Octave wiki.

-- 
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
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]