Hi Zach,
On 29.05.2017 22:57, Zach Morris wrote:
Hi Marcus,
Sorry about the trouble with Nabble, I see that my code got
cut off. I will communicate via the mailing list from now on.
If I understand your explanation correctly, the forecast
function below tells the scheduler that this block needs at
least noutput_items on each input port in order to produce
noutput_items. In actuality, my arbitrary ratio block would
produce anywhere between (0, noutput_items); would this be a
valid implementation of forecast() for my arbitrary ratio
block?
def forecast(self, noutput_items, ninput_items_required):
for i in range(len(ninput_items_required)):
ninput_items_required[i] = noutput_items
yes, that would tell the scheduler that you'll need at least
noutput_items input items to produce noutput_items output items,
indeed!
Now, the forecast really is just that: a forecast. If you can't
produce as many samples as promised, the scheduler won't be upset.
This is my general_work() function right now: it just
outputs the elements in the input vector that are above a
threshold. My eventual goal is to receive a vector from an
FFT and update statistics for each frequency 'bin' as long
as its power is above a threshold, then output the
statistics when its power drops below the threshold.
def general_work(self, input_items, output_items):
in0 = input_items[0][:len(output_items[0])]
This is **only** OK if you check that len(output_items[0]) <=
len(input_items[0]). You inherently do that with your forecast, but
I'd really recommend explicitly checking that condition.
Also, this the following code is really very redundant:
out0 = output_items[0]
ninput_items = len(in0)
well, you set in0 to be of len(output_items[0]).
j = 0
for i in range(0, ninput_items):
this is very un-pythonic.
if (in0[i] > self.threshold).all():
out0[j] = in0[i]
j += 1
I'd just say:
def general_work(self, input_items, output_items):
super_threshold = filter(lambda x: x > self.threshold, in[0])
output_items[0][:] = super_threshold
self.consume_each(len(super_threshold))
return len(super_threshold)
Best regards,
Marcus
self.consume(0, ninput_items)
self.produce(0, j)
return 0
If I again understand your explanation, the
'self.consume(0, ninput_items)' is correct, because I 'use up'
the elements of input_items on each loop. However, it sounds
like I should either return WORK_CALLED_PRODUCE or return
ninput_tems. Am I on the right track here? Is there a reason
to prefer produce() over just returning the number of input
items I consume?
Thank you for your help.
Zach
|