# Python pass parameter as const \*gr\_complex?

**URL:** <https://www.ruby-forum.com/t/python-pass-parameter-as-const-gr-complex/233739>\
**Category:** GNU Radio\
**Created:** [January 7, 2015, 2:50pm UTC](https://www.ruby-forum.com/t/python-pass-parameter-as-const-gr-complex/233739 "2015-01-07T14:50:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [January 7, 2015, 2:50pm UTC](https://www.ruby-forum.com/t/python-pass-parameter-as-const-gr-complex/233739/1 "2015-01-07T14:50:40Z")

</div>

Hi list,

I am trying to use the gr::digital::constellation::decision\_maker(.)  
method from python, but I get an error message.  
In order to reproduce call in python:

import gnuradio.digital  
a = gnuradio.digital.constellation\_qpsk()  
b = complex(1+1j)  
a.decision\_maker(b)  
=\> TypeError […] argument 2 of type ‘gr\_complex const\*’  
The C+±implementation is wrapped by SWIG, where the error occurs.

This might be a silly question, but what am I doing wrong?

Thanks for any help.

Best regards

Stephan Ludwig

Robert Bosch GmbH  
Corporate Sector Research & Advance Engineering, Communication  
Technology (CR/AEH4)  
Renningen  
70465 Stuttgart  
GERMANY  
[www.bosch.com](http://www.bosch.com)[http://www.bosch.com](http://www.bosch.com)

Tel. +49(711)811-8809  
Fax +49(711)811-1052  
Mobile +49(172)5630639  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Registered Office: Stuttgart, Registration Court: Amtsgericht Stuttgart,  
HRB 14000;  
Chairman of the Supervisory Board: Franz Fehrenbach; Managing Directors:  
Dr. Volkmar Denner,  
Dr. Stefan Asenkerschbaumer, Dr. Rolf Bulander, Dr. Stefan Hartung, Dr.  
Dirk Hoheisel, Christoph Kbel,  
Uwe Raschke, Wolf-Henning Scheider, Dr. Werner Struth, Peter Tyroller

---

<div class="post-metadata">

**Author:** ![Ludwig\_Stephan\_SCR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e36b37/32.png) [@Ludwig\_Stephan\_SCR](https://www.ruby-forum.com/u/Ludwig_Stephan_SCR)\
**Post date:** [January 20, 2015, 3:58pm UTC](https://www.ruby-forum.com/t/python-pass-parameter-as-const-gr-complex/233739/2 "2015-01-20T15:58:24Z")

</div>

On Wed, Jan 7, 2015 at 7:57 AM, Ludwig Stephan (CR/AEH4) \<  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:

> =\> TypeError [..] argument 2 of type ‘gr\_complex const\*’  
> The C+±implementation is wrapped by SWIG, where the error occurs.
> 
> This might be a silly question, but what am I doing wrong?
> 
> Thanks for any help.
> 
> Best regards
> 
> _Stephan Ludwig_

Hi Stephan,

You’re not doing anything wrong per se, but the block isn’t really meant  
to  
be used that way. SWIG needs to be told how to handle some types of  
argument formats, and it hasn’t been told how to handle this one.

The post 3.7 way we’ve been handling SWIG is to just include the public  
.h  
file as the interface, so all methods are exported into SWIG. A class  
like  
this needs that method to be public for use as a contained object in the  
block that calls it, but it’s not really meant for use outside like  
this.  
Not that it couldn’t be, but you’d have to work with SWIG to let it  
understand how to call that function with the proper input type.

Tom

---

<div class="post-metadata">

**Author:** ![Ludwig\_Stephan\_SCR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e36b37/32.png) [@Ludwig\_Stephan\_SCR](https://www.ruby-forum.com/u/Ludwig_Stephan_SCR)\
**Post date:** [January 21, 2015, 9:14am UTC](https://www.ruby-forum.com/t/python-pass-parameter-as-const-gr-complex/233739/3 "2015-01-21T09:14:42Z")

</div>

Thank you, Tom, for your enlightening answer. Please let me ask two  
additional questions:

1. If I understood your explanation correctly, as a consequence of this,  
one could not use the decision\_maker method within a block, which is  
coded solely in python. Right?

2. Isn’t “const gr\_complex\*” a type, which is used very often in the  
block I/O interfaces, and shouldn’t, thus, the GR configuration of SWIG  
already let it know how to translate python/complex to gr\_complex?

Best regards

Stephan Ludwig

Robert Bosch GmbH  
Corporate Sector Research & Advance Engineering, Communication  
Technology (CR/AEH4)  
Renningen  
70465 Stuttgart  
GERMANY

> **[Want to know how to live #LikeABosch?](https://www.bosch.com/)**
>
> Moving stories and inspiring interviews. Experience the meaning of "invented for life" by Bosch completely new. Visit our international website.

Tel. +49(711)811-8809  
Fax +49(711)811-1052  
Mobile +49(172)5630639  
removed\_email\_address@domain.invalid

Registered Office: Stuttgart, Registration Court: Amtsgericht Stuttgart,  
HRB 14000;  
Chairman of the Supervisory Board: Franz Fehrenbach; Managing Directors:  
Dr. Volkmar Denner,  
Dr. Stefan Asenkerschbaumer, Dr. Rolf Bulander, Dr. Stefan Hartung, Dr.  
Dirk Hoheisel, Christoph Kübel,  
Uwe Raschke, Wolf-Henning Scheider, Dr. Werner Struth, Peter Tyroller  
Von: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] Im Auftrag von  
Tom R.  
Gesendet: Dienstag, 20. Januar 2015 15:57  
An: Ludwig Stephan (CR/AEH4)  
Cc: removed\_email\_address@domain.invalid  
Betreff: Re: [Discuss-gnuradio] Python pass parameter as const  
\*gr\_complex?

On Wed, Jan 7, 2015 at 7:57 AM, Ludwig Stephan (CR/AEH4)  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
Hi list,

I am trying to use the gr::digital::constellation::decision\_maker(.)  
method from python, but I get an error message.  
In order to reproduce call in python:

import gnuradio.digital  
a = gnuradio.digital.constellation\_qpsk()  
b = complex(1+1j)  
a.decision\_maker(b)  
=\> TypeError […] argument 2 of type ‘gr\_complex const\*’  
The C+±implementation is wrapped by SWIG, where the error occurs.

This might be a silly question, but what am I doing wrong?

Thanks for any help.

Best regards

Stephan Ludwig

Hi Stephan,

You’re not doing anything wrong per se, but the block isn’t really meant  
to be used that way. SWIG needs to be told how to handle some types of  
argument formats, and it hasn’t been told how to handle this one.

The post 3.7 way we’ve been handling SWIG is to just include the public  
.h file as the interface, so all methods are exported into SWIG. A class  
like this needs that method to be public for use as a contained object  
in the block that calls it, but it’s not really meant for use outside  
like this. Not that it couldn’t be, but you’d have to work with SWIG to  
let it understand how to call that function with the proper input type.

Tom

---

<div class="post-metadata">

**Author:** ![Ludwig\_Stephan\_SCR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e36b37/32.png) [@Ludwig\_Stephan\_SCR](https://www.ruby-forum.com/u/Ludwig_Stephan_SCR)\
**Post date:** [January 21, 2015, 2:51pm UTC](https://www.ruby-forum.com/t/python-pass-parameter-as-const-gr-complex/233739/4 "2015-01-21T14:51:45Z")

</div>

On Wed, Jan 21, 2015 at 3:13 AM, Ludwig Stephan (CR/AEH4) \<  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:

> Thank you, Tom, for your enlightening answer. Please let me ask two  
> additional questions:
> 
> 1. If I understood your explanation correctly, as a consequence of this,  
> one could not use the decision\_maker method within a block, which is coded  
> solely in python. Right?

Correct.

> 1. Isn’t “const gr\_complex\*” a type, which is used very often in the block  
> I/O interfaces, and shouldn’t, thus, the GR configuration of SWIG already  
> let it know how to translate python/complex to gr\_complex?

No. That type is almost never used. What is often used is “const  
std::vector\<gr\_complex\>”. But again, this class was designed to be  
called  
from within a block’s work function, so the data structure would have  
already been a “const gr\_complex\*” (casting the input\_items argument).

Tom

---

<div class="post-metadata">

**Author:** ![Ludwig\_Stephan\_SCR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e36b37/32.png) [@Ludwig\_Stephan\_SCR](https://www.ruby-forum.com/u/Ludwig_Stephan_SCR)\
**Post date:** [January 21, 2015, 4:27pm UTC](https://www.ruby-forum.com/t/python-pass-parameter-as-const-gr-complex/233739/5 "2015-01-21T16:27:41Z")

</div>

Hi Tom,

thank you for clarification. The problem arose, when I wanted to use the  
method from within a _python_block’s work function. But I understood,  
that this is not possible (a.t.m.), and I will write a C++ clock, which  
should perform better anyways 😉

Best regards

Stephan Ludwig

Robert Bosch GmbH  
Corporate Sector Research & Advance Engineering, Communication  
Technology (CR/AEH4)  
Renningen  
70465 Stuttgart  
GERMANY  
[www.bosch.com](http://www.bosch.com)[http://www.bosch.com](http://www.bosch.com)

Tel. +49(711)811-8809  
Fax +49(711)811-1052  
Mobile +49(172)5630639  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Registered Office: Stuttgart, Registration Court: Amtsgericht Stuttgart,  
HRB 14000;  
Chairman of the Supervisory Board: Franz Fehrenbach; Managing Directors:  
Dr. Volkmar Denner,  
Dr. Stefan Asenkerschbaumer, Dr. Rolf Bulander, Dr. Stefan Hartung, Dr.  
Dirk Hoheisel, Christoph Kübel,  
Uwe Raschke, Wolf-Henning Scheider, Dr. Werner Struth, Peter Tyroller  
Von: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] Im Auftrag von  
Tom R.  
Gesendet: Mittwoch, 21. Januar 2015 14:50  
An: Ludwig Stephan (CR/AEH4)  
Cc: removed\_email\_address@domain.invalid  
Betreff: Re: [Discuss-gnuradio] Python pass parameter as const  
\*gr\_complex?

On Wed, Jan 21, 2015 at 3:13 AM, Ludwig Stephan (CR/AEH4)  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\>  
wrote:  
Thank you, Tom, for your enlightening answer. Please let me ask two  
additional questions:

1. If I understood your explanation correctly, as a consequence of this,  
one could not use the decision\_maker method within a block, which is  
coded solely in python. Right?

Correct.

1. Isn’t “const gr\_complex\*” a type, which is used very often in the  
block I/O interfaces, and shouldn’t, thus, the GR configuration of SWIG  
already let it know how to translate python/complex to gr\_complex?

No. That type is almost never used. What is often used is “const  
std::vector\<gr\_complex\>”. But again, this class was designed to be  
called from within a block’s work function, so the data structure would  
have already been a “const gr\_complex\*” (casting the input\_items  
argument).

Tom

Best regards

Stephan Ludwig

Robert Bosch GmbH  
Corporate Sector Research & Advance Engineering, Communication  
Technology (CR/AEH4)  
Renningen  
70465 Stuttgart  
GERMANY  
[www.bosch.com](http://www.bosch.com)[http://www.bosch.com](http://www.bosch.com)

Tel. +49(711)811-8809tel:%2B49(711)811-8809  
Fax +49(711)811-1052tel:%2B49(711)811-1052  
Mobile +49(172)5630639tel:%2B49(172)5630639  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Registered Office: Stuttgart, Registration Court: Amtsgericht Stuttgart,  
HRB 14000;  
Chairman of the Supervisory Board: Franz Fehrenbach; Managing Directors:  
Dr. Volkmar Denner,  
Dr. Stefan Asenkerschbaumer, Dr. Rolf Bulander, Dr. Stefan Hartung, Dr.  
Dirk Hoheisel, Christoph Kübel,  
Uwe Raschke, Wolf-Henning Scheider, Dr. Werner Struth, Peter Tyroller  
Von: removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] Im Auftrag  
von Tom R.  
Gesendet: Dienstag, 20. Januar 2015 15:57  
An: Ludwig Stephan (CR/AEH4)  
Cc: removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Betreff: Re: [Discuss-gnuradio] Python pass parameter as const  
\*gr\_complex?

On Wed, Jan 7, 2015 at 7:57 AM, Ludwig Stephan (CR/AEH4)  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\>  
wrote:  
Hi list,

I am trying to use the gr::digital::constellation::decision\_maker(.)  
method from python, but I get an error message.  
In order to reproduce call in python:

import gnuradio.digital  
a = gnuradio.digital.constellation\_qpsk()  
b = complex(1+1j)  
a.decision\_maker(b)  
=\> TypeError […] argument 2 of type ‘gr\_complex const\*’  
The C+±implementation is wrapped by SWIG, where the error occurs.

This might be a silly question, but what am I doing wrong?

Thanks for any help.

Best regards

Stephan Ludwig

Hi Stephan,

You’re not doing anything wrong per se, but the block isn’t really meant  
to be used that way. SWIG needs to be told how to handle some types of  
argument formats, and it hasn’t been told how to handle this one.

The post 3.7 way we’ve been handling SWIG is to just include the public  
.h file as the interface, so all methods are exported into SWIG. A class  
like this needs that method to be public for use as a contained object  
in the block that calls it, but it’s not really meant for use outside  
like this. Not that it couldn’t be, but you’d have to work with SWIG to  
let it understand how to call that function with the proper input type.

Tom
