[SciPy-user] swig and numpy.i

Matthieu Brucher matthieu.brucher@gmail....
Sat Oct 13 06:55:19 CDT 2007


In fact, you would want to have res being an array with the same dimensions
than v ?
In that case, you could define a new function with an additional size
parameter, check that the two sizes are equal and then call your function.


2007/10/11, Jaonary Rabarisoa <jaonary@gmail.com>:
> Hi all,
> I'm trying to write a c++ code that I need to call in python and is able
> to use numpy and scipy.
> I've already read the documentation about the numpy.i interface file and
> succed to use it correctly when I want to pass an array as argument of my
> function. In other words, I've tried something like this :
> in the file "sum.h"
> double sum(double* v,int n); // a function the compute the sum of the
> element of v
> in the swig interface file "sum.i"
> %module mysum
> %{
> #include "sum.h"
> %}
> %include "numpy.i"
> %init %{
> import_array();
> %}
> %apply(double* IN_ARRAY1,int DIM1){(double* v,int n)}
> %include "sum.h"
> This thing  works correctly and I'm happy. But  now I'd like to do
> something a little bit complicated.  I'd like to  use a function that uses
> not only an array but another argument such as scalar. For example, I need
> to wrap the following C++ code :
> void multiply(double* v,int  n,double  a,double* res);  // this  code
> will multiply all  elements of v by a and return a new  vector that contain
> the result, res[i] = v[i]*a. And here comes the problem, I cant figure out
> how to use the numpy.i interface file to do this.
> Any tips and help will be appreciated.
> Best regards,
> Jaonary
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20071013/d5d7b3be/attachment.html 

More information about the SciPy-user mailing list