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

Michel Dupront michel.dupront@hotmail...
Wed Sep 24 06:59:58 CDT 2008

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.
Here is what was supposed to be a very simple example.
void globale_print(std::vector vint)
  std::cout<<"globale print vecteur: ";
  for (size_t i=0; i
  PyArrayObject* aa=(PyArrayObject *) $input;
  for (unsigned int i=0; idimensions[0]; i++)
    $1[i]= *(int *) (aa->data + i* aa->strides[0] );
%include "example.h"
import example
import Numeric
print array
print type(array)
Like it is, it works. But there are a lot of things that I don't
For example if I want to check aa, like:
  if (!PyArray_Check(aa)) {
    return NULL;
the compilation of the wrapper is ok but when I run the python
script runme.py, I have a segmentation fault because of the first line.
Here I really need help.
Please keep in mind that it is my first try to make a typemap ....
Thanks a lot
Installez gratuitement les 20 émôticones Windows Live Messenger les plus fous ! Cliquez ici !

More information about the Numpy-discussion mailing list