On 06/06/2012 09:52 AM, Martin Braun wrote: > On Sat, Jun 02, 2012 at 10:52:50AM -0700, Josh Blum wrote: >> Most of the description is in the wiki page: >> https://github.com/guruofquality/grextras/wiki >> >> And here is a handy coding guide for more detail: >> https://github.com/guruofquality/grextras/wiki/Blocks-Coding-Guide > > Hi Josh, > > I'm not quite behind all of this yet. Here's two questions, if you could > spare a minute: > > First thing I tried was the Python blocks, and I wrote a random number > generator (yep, I know that already exists, but I just wanted something > simple to start with). > Q: Why can't I assign arrays to output_items? See the code: > > <snip> > from gnuradio import gr > import gnuradio.extras > import numpy > MAXRND = 1000 > > class rng_i(gr.block): > " random number generator " > def __init__(self): > gr.block.__init__(self, name="rng_i", in_sig=None, > out_sig=[numpy.int32]) > > def work(self, input_items, output_items): > # Doesn't work: > #output_items[0] = numpy.array(numpy.random.randint(0, MAXRND, > len(output_items[0])), dtype=numpy.int32)[:]
I think I documented something about the numpy index operator, but maybe I deleted it... have to check. Basically, use the indexing operator on the left side of the assignment. output_items[0][:] = numpy.array(numpy.random.randint(0, MAXRND, len(output_items[0])), dtype=numpy.int32) > # Works: > for i in xrange(len(output_items[0])): > output_items[0][i] = numpy.random.randint(0, MAXRND) > return len(output_items[0]) > </snip> > > I'm assuming it's something like copy vs. reference, but I thought I was > doing everything right. > > > Q: The first argument of post_msg, is this simply == the number of > stream ports? Say I have one stream output and one msg output, do I > always post to port 1? > Reason I ask is you mention 'group indexes' and I'm not sure what that > means. > The group index refers to the index of the message source ports. This would be zero for the 1st message source port. I should clarify that in the docs... :-) > Apart from that, I quite like your code and would like to lobby towards > getting some of it into the mainline repository. Now I just have to come > up with something useful to do with it :) > Thanks for trying it out. -josh _______________________________________________ Discuss-gnuradio mailing list [email protected] https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
