Cumsum block on GRC

Hi List,

I am trying to write a block, that finds the cumulative sum of the
points.
But when i run the block on GRC, the output of the block becomes as in
the attached figure. It wraps for a period of time. I expect it to go
negatively downwards. Because i am accumulating negative values. I
couldn’t understand the reason. Is there something missing in the
code. The c++ code of the block is attached also.

Thanks for the help!
Mehmet.

On Sat, 2011-05-07 at 15:53 +0100, Tom R. wrote:

    negatively downwards. Because i am accumulating negative

Mehmet,
It looks like it’s because you are setting out[0] = 0 before entering
the for loop in your work function. This will then reset the counter
every time you enter work.

I’m pretty sure it won’t work even if you remove that call. You can’t
count on out[0] having any sort of reasonable value when invoking the
work call. Try saving the cumulative sum in a private member variable of
your class, initialize it to 0 in your constructor, and setting out[0]
to that saved value when starting each work function call.

–n

Hi Nick,

I made the change you suggested and it worked, thanks a lot.

Mehmet.

2011/5/7, Nick F. [email protected]:

On Sat, May 7, 2011 at 3:44 PM, mehmet kabasakal
[email protected]wrote:

Mehmet.
Mehmet,
It looks like it’s because you are setting out[0] = 0 before entering
the
for loop in your work function. This will then reset the counter every
time
you enter work.

Tom

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs