[Numpy-discussion] SWIG Numpy and C++ extensions

Doutriaux, Charles doutriaux1@llnl....
Mon Jul 30 17:45:08 CDT 2012


Hi,

I have wrapped a c++ code with SWIG.

Now that code used to read input from ASCII files. I'm trying to replace that part with an input coming from numpy.

I would rather not use setup.py if I have to (but if I can't avoid fine)

I'm looking at SWIG/numpy tutorials

looks like you need to do something like
%apply

2 questions:
1- How do use "apply" for class functions %apply (bla) myobject::foo ?
2-that's ok if your C++ deals with arrays but what if I actually want to receive the Numpy object so that I can manipulate it directly (or if for example the array isn't contiguous in memory)

An"dummy"example of foo function I'd like to wrap:

     void FOO::fooNumpy(PyArrayObject *nparray) {

      int j;
      for(j=0;j<nparray->nd;j++) {
printf("Ok array dim %i has length: %i\n",j,nparray->dimensions[j]);
      }
    }


Thanks,

C.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20120730/46b112a5/attachment-0001.html 


More information about the NumPy-Discussion mailing list