# Python block, itemsize mismatch

**URL:** <https://www.ruby-forum.com/t/python-block-itemsize-mismatch/239690>\
**Category:** GNU Radio\
**Created:** [March 10, 2014, 6:59pm UTC](https://www.ruby-forum.com/t/python-block-itemsize-mismatch/239690 "2014-03-10T18:59:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [March 10, 2014, 6:59pm UTC](https://www.ruby-forum.com/t/python-block-itemsize-mismatch/239690/1 "2014-03-10T18:59:23Z")

</div>

Hi,

I get the following error connecting ‘OFDM Serializer’ (GNU Radio block  
with complex output), to my own Python block ‘blsd\_dec\_bfb’ (with  
complex input)

“ValueError: itemsize mismatch: ofdm\_serializer\_vcc0:0 using 8,  
blsd\_dec\_bfb0:0 using 16”

This is the code in the beginning of my block

“class blsd\_dec\_bfb(gr.basic\_block):  
“””  
docstring for block blsd\_dec\_bfb  
“”"  
def **init** (self, num\_packets=1, K=50, K2=20, kA1=4, NA1=8,  
num\_carriers=64):  
gr.basic\_block. **init** (self,  
name=“blsd\_dec\_bfb”,  
in\_sig=[numpy.complex],  
out\_sig=[numpy.uint8,numpy.uint8,numpy.uint8])"

the xml is

"…   
in  
complex

 bA1 byte bA2 byte b2 byte ..."

The colours match in the GRC, and it lets me run it (i.e. no complaints  
about type mismatch before run-time).

I hope it is just a silly mistake. Can anyone help?

Regards,

David

* * *

NOTE: The information in this email and any attachments may be  
confidential and/or legally privileged. This message may be read, copied  
and used only by the intended recipient. If you are not the intended  
recipient, please destroy this message, delete any copies held on your  
system and notify the sender immediately.

Toshiba Research Europe Limited, registered in England and Wales  
(2519556). Registered Office 208 Cambridge Science Park, Milton Road,  
Cambridge CB4 0GZ, England. Web: www.toshiba.eu/research/trl

---

<div class="post-metadata">

**Author:** ![divotdave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bbe5ce/32.png) [@divotdave](https://www.ruby-forum.com/u/divotdave)\
**Post date:** [March 10, 2014, 10:30pm UTC](https://www.ruby-forum.com/t/python-block-itemsize-mismatch/239690/2 "2014-03-10T22:30:55Z")

</div>

On 03/10/2014 06:57 PM, David Halls wrote:

> “class blsd\_dec\_bfb(gr.basic\_block):  
> “””  
> docstring for block blsd\_dec\_bfb  
> “”"  
> def **init** (self, num\_packets=1, K=50, K2=20, kA1=4, NA1=8,  
> num\_carriers=64):  
> gr.basic\_block. **init** (self,  
> name=“blsd\_dec\_bfb”,  
> in\_sig=[numpy.complex],  
> out\_sig=[numpy.uint8,numpy.uint8,numpy.uint8])"

I think you need to do numpy.complex64 – not 100%, can you please tell  
us if this worked.

M

---

<div class="post-metadata">

**Author:** ![divotdave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bbe5ce/32.png) [@divotdave](https://www.ruby-forum.com/u/divotdave)\
**Post date:** [March 11, 2014, 1:46am UTC](https://www.ruby-forum.com/t/python-block-itemsize-mismatch/239690/3 "2014-03-11T01:46:42Z")

</div>

On Tue, Mar 11, 2014 at 5:29 AM, Martin B.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> > This is the code in the beginning of my block  
> > out\_sig=[numpy.uint8,numpy.uint8,numpy.uint8])"
> 
> I think you need to do numpy.complex64 – not 100%, can you please tell  
> us if this worked.
> 
> M
> 
> > The colours match in the GRC, and it lets me run it (i.e. no complaints  
> > about type mismatch before run-time).

The “float” and “gr\_complex” data type in c++ usually match with  
“numpy.float32” and “numpy.complex64” in python.  
The “int” in c++ matches “numpy.int32” in python.  
So far I haven’t encountered any exception.

c++ python

---

<div class="post-metadata">

**Author:** ![divotdave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bbe5ce/32.png) [@divotdave](https://www.ruby-forum.com/u/divotdave)\
**Post date:** [March 11, 2014, 9:34am UTC](https://www.ruby-forum.com/t/python-block-itemsize-mismatch/239690/4 "2014-03-11T09:34:22Z")

</div>

On 03/11/2014 02:06 AM, David Halls wrote:

> You’re a genius! It works.
> 
> Interestingly for a float it requires numpy.float32 or a similar error  
> occurs.

Yes, in GNU Radio we consistently use 32-bit floats. A complex value  
consists of two of these, hence the 64 bits.

Note that this is just for buffers. A lot of blocks use double  
internally (i.e. 64-bit float, or 128-bit complex) for accuracy reason.  
However, for signals, it’s just a waste of bandwidth (most of time, SNR  
will trump quantization noise anyway).

M

---

<div class="post-metadata">

**Author:** ![divotdave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bbe5ce/32.png) [@divotdave](https://www.ruby-forum.com/u/divotdave)\
**Post date:** [March 11, 2014, 2:07am UTC](https://www.ruby-forum.com/t/python-block-itemsize-mismatch/239690/5 "2014-03-11T02:07:59Z")

</div>

You’re a genius! It works.

Interestingly for a float it requires numpy.float32 or a similar error  
occurs.

D

* * *

From: [discuss-gnuradio-bounces+david.halls=removed\_email\_address@domain.invalid](mailto:discuss-gnuradio-bounces+david.halls=removed_email_address@domain.invalid)  
[discuss-gnuradio-bounces+david.halls=removed\_email\_address@domain.invalid] on  
behalf of Martin B. [removed\_email\_address@domain.invalid]  
Sent: 10 March 2014 21:29  
To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Re: [Discuss-gnuradio] Python block, itemsize mismatch

On 03/10/2014 06:57 PM, David Halls wrote:

> “class blsd\_dec\_bfb(gr.basic\_block):  
> “””  
> docstring for block blsd\_dec\_bfb  
> “”"  
> def **init** (self, num\_packets=1, K=50, K2=20, kA1=4, NA1=8,  
> num\_carriers=64):  
> gr.basic\_block. **init** (self,  
> name=“blsd\_dec\_bfb”,  
> in\_sig=[numpy.complex],  
> out\_sig=[numpy.uint8,numpy.uint8,numpy.uint8])"

I think you need to do numpy.complex64 – not 100%, can you please tell  
us if this worked.

M

> about type mismatch before run-time). confidential and/or legally privileged. This message may be read, copied ------------------------------------------------------------------------

* * *

Discuss-gnuradio mailing list  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> **[Discuss-gnuradio Info Page](https://lists.gnu.org/mailman/listinfo/discuss-gnuradio)**

* * *

NOTE: The information in this email and any attachments may be  
confidential and/or legally privileged. This message may be read, copied  
and used only by the intended recipient. If you are not the intended  
recipient, please destroy this message, delete any copies held on your  
system and notify the sender immediately.

Toshiba Research Europe Limited, registered in England and Wales  
(2519556). Registered Office 208 Cambridge Science Park, Milton Road,  
Cambridge CB4 0GZ, England. Web: www.toshiba.eu/research/trl
