[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Vectorizing simple loops
From: |
Jose Marcos Ferraro |
Subject: |
RE: Vectorizing simple loops |
Date: |
Mon, 7 Dec 2015 18:07:34 +0000 |
-----Original Message-----
From: address@hidden [mailto:address@hidden On Behalf Of pawelz
Sent: domingo, 6 de dezembro de 2015 21:03
To: address@hidden
Subject: RE: Vectorizing simple loops
Jose, Thank you very much for working on it. I just tested your solution and
its results match perfectly with the original function even on big data sets.
The performance is over 200 times better, so it is exactly what I needed.
Now, would you be so kind to explain the train of thought in this algorithm?
I'd very much like to understand it better.
--
View this message in context:
http://octave.1599824.n4.nabble.com/Vectorizing-simple-loops-tp4673742p4673860.html
Sent from the Octave - General mailing list archive at Nabble.com.
_______________________________________________
Help-octave mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/help-octave
Pawel,
your finite state machine is very peculiar, to the point that I though I had
misunderstood it.
If the accumulator is positive and the input is -1 or -2, it forgets the old
value and start again from zero. The same thing happens if the acc is negative
and input is +1 or +2.
So we can separate in two parts , a positive and a negative one. That's why the
intermediate variables have a positive"up" and negative "down" version.
Each of this two parts is independent and can be calculated separetedly.
Finally, inside each part there is a certain number of "runs" inside which the
accumulator simply goes up till it reaches top.
When it reaches top it will not change anymore till the end of the run, so one
can simply ignore it and later clean the values that go higher (or lower) then
allowed.
So inside each run it behaves as a simple accumulator increasing at 2 and doing
nothing at 0 or 1.
If you are really concerned about performance, it can most likely be improved.
This is simply the first version that I wrote and that I believe is simpler to
understand.
The code can certainly also be factored, as someone pointed on this list and as
the evident analogy between the up and down variables show the duplication of
code.
Jose Marcos Ferraro
www.LOGITeng.com
- Re: Vectorizing simple loops, (continued)