[Numpy-discussion] A basic question about swig and Numeric
Michel Dupront
michel.dupront at hotmail.fr
Wed Sep 24 07:59:58 EDT 2008
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.
Here is what was supposed to be a very simple example.
example.h:
#include
#include
void globale_print(std::vector vint)
{
std::cout<<"globale print vecteur: ";
for (size_t i=0; i
{
PyArrayObject* aa=(PyArrayObject *) $input;
$1.resize(aa->dimensions[0]);
for (unsigned int i=0; idimensions[0]; i++)
{
$1[i]= *(int *) (aa->data + i* aa->strides[0] );
}
};
%include "example.h"
runme.py:
import example
import Numeric
array=Numeric.array(range(5))
print array
print type(array)
example.globale_print(array)
Like it is, it works. But there are a lot of things that I don't
understand.
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
Michel
_________________________________________________________________
Installez gratuitement les 20 émôticones Windows Live Messenger les plus fous ! Cliquez ici !
http://www.emoticones-messenger.fr/
More information about the NumPy-Discussion
mailing list