[Numpy-discussion] Global Numpy vector with Swig

Andrea Tomadin tom.and at tiscalinet.it
Fri Feb 16 12:59:35 EST 2007


Il giorno 15/feb/07, alle ore 22:26, Bill Spotz ha scritto:

> It seems to me you would need to %ignore vec, so that it is not  
> wrapped as a raw pointer to a double, and then in your interface  
> file create a PyArrayObject whose data buffer points to vec (the  
> most efficient way to do this is with %inline).  Then use %rename  
> to rename whatever you called your PyArrayObject to "vec" (or not,  
> if you do not care about the name).  Finally,
>
>   foo.cvar.vec = numpy.zeros(10)
>
> is going to decrement (and probably delete) your original vec and  
> replace it with the new array of zeros (I think,

Thank you Bill for your help, even if writing this code is not  
straightforward for me. Anyway, while I was reading the docs, I  
became aware of the varin, varout typemap options. I wonder if I can  
define a
typemap(varin) double *
declaration, and insert in it the same code that in "numpy.i"  
translates the PyArrayObject into a C array and vice versa.
But I cannot find an example of typemp(varin) for Python, so I don't  
know what to use for the output, instead of $1. Where are the typemaps 
(varin) for Python?
It seems strange that nobody wrote a public code for such a simple  
task, as I read that Swig supports Python since the 90s! I suspect I  
have just not looked in the right places?!

Thank you again for help!
Andrea




More information about the NumPy-Discussion mailing list