[Numpy-discussion] A basic question about swig and Numeric

Russell E. Owen rowen@u.washington....
Thu Sep 25 14:45:49 CDT 2008

In article <BAY144-W4884C4D9C7A96C6A5DB601F4450@phx.gbl>,
 Michel Dupront <michel.dupront@hotmail.fr> wrote:

> Hello,
> I am trying to use Numeric and swig but it seems that
> there are few points that I don't understand. 
> The only excuse I have is that I am new to these tools.
> I have a simple example that I cannot make work the 
> way I would like. 
> I have a c++ function that take as argument a std::vector.
> >From python I want to call the c++ function with an array
> object. For that purpose I want to write a typemap.

Would this suffice:
%include "std_vector.i"
%template(vectorF) std::vector<float>;
%template(vectorD) std::vector<double>;

This will certainly make a SWIGged function accept a list where a vector 
of floats or doubles is expected (and you can expand the types of 
course). I'm not sure it'll take a numpy or Numeric array of float or 
double, but if not then perhaps you can read the code in std_vector.i 
and see how it works.

-- Russell

More information about the Numpy-discussion mailing list