[C++-sig] Simply calling a routine ...

Nicodemus nicodemus at globalite.com.br
Sun Apr 27 20:42:34 CEST 2003

christophe grimault wrote:

> Hi all,
> I have a written several routines in C++ using blitz++. These
> routines are called sucessively by the 'main' routine. I want to 
> rewrite the main in python in order to gain development speed and 
> flexibility. The routines use blitz++ matrix template library
> but the interfaces to the routine are very common C++ calls with
> basic C++ types (int, float*, short*, etc...) :
> int foo( short* a, float b, float* c, int N ){
>     Array<short, 1> A(N);
>     A.data() = a;
>     // Do some work
>     return ( ERROR_CODE );
> }
> Is it straightforward to declare these routines with pyste
> (or the classic boost method). Does the use of blitz in these
> routines (which belong to another file than the main, beginning
> with include of blitz.hh) complicates the process. I'm a bit lost 
> because of the use of "templates in blitz++" versus "integration with 
> boost". 

What problems are you having exactly? And I don't know how you would 
pass the parameters to this function, except if you create the arrays in 
C++ too. If you don't care about reading the array values in Python, you 
can treat them as opaque pointers... check return_opaque_pointer:


> Also, as you can see in the example routine above, I started with
> a creation of a blitz array 'A' from the array 'a'. Because I'm
> afraid of the work to get back and forth from Numeric array in Python
> to Blitz++ templated Array in C++ is a complicated and big amount
> of work. 

Perhaps, but I don't believe it would be such a pain... you can create 
simple wrappers that would do the job nicely; If there is a lot of 
functions, then perhaps you could even implement to-python and 
from-python conversions for Numeric arrays, as demonstrated here (for 
C++ standard containers):


> Thanks for any response on these to points, and for any suggestion or
> criticism on my way of handling the problem.    
> Christophe Grimault

Hope that helps!


More information about the Cplusplus-sig mailing list