Hi Igor, no, forecast() does **not** require your to predict the number of output items.
It **gives** you a number of output items and a vector, into which you fill in your **forecast of the necessary input items**: Where's that documentation you're referring to? Maybe we have to improve that! anyway, I must admit that I don't understand what your block does. What is a "sequence"? Best regards, Marcus On 01/28/2017 07:03 PM, Igor Volodin wrote: > Hi all, > > I am creating a block which will count number of "1" values in a > sequence, and output it number (I am trying to convert PWM encoded bits). > Block has 1 input (numpy.int32) and 1 output (it's also has > numpy.int32 type) > > So, it should work following way: > > [1,1,1,0,0,1,0,0,0,1,1,1,1,1] -> [MyBlock] -> [3,1,5] > > Documentation says that i should predict number of output items in a > forecast() method. But i can't predict how many sequences will be in > the input items. > Could anybody suggest a solution for this case? > > Here is my Python code: > > > import numpy > from gnuradio import gr > > class hold_and_sum(gr.basic_block): > """ > docstring for block hold_and_sum > """ > def __init__(self): > gr.basic_block.__init__(self, name="hold_and_sum", > in_sig=[numpy.int32], out_sig=[numpy.int32]) > self.summary = numpy.int32(0) > self.in_accumulation = 0 > self.out_bytes = [numpy.int32] > > def forecast(self, noutput_items, ninput_items_required): > #setup size of input_items[i] for work call > for i in range(len(ninput_items_required)): > ninput_items_required[i] = noutput_items > > def general_work(self, input_items, output_items): > in0 = input_items[0] > out = output_items[0] > for smpl in in0: > if smpl == 1: > self.in_accumulation = 1 > self.summary = numpy.sum([self.summary, smpl], > dtype=numpy.int32) > else: > if (self.in_accumulation == 1): #previous sample was > 1, and now we have 0, it's end of a pulse > print self.summary # print pulse length > self.out_bytes.append(self.summary) > self.summary = 0 #empty counter > self.in_accumulation = 0 #Reset flag > print self.out_bytes > if len(self.out_bytes) == 0: > self.out_bytes.append(0) > #out[:] = numpy.array(self.out_bytes) ??? > del self.out_bytes[:] > #self.consume(0, len(input_items[0])) > self.consume_each(len(input_items[0])) > return (len(out)) > > > > Best regards, > Igor > > _______________________________________________ > Discuss-gnuradio mailing list > [email protected] > https://lists.gnu.org/mailman/listinfo/discuss-gnuradio _______________________________________________ Discuss-gnuradio mailing list [email protected] https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
