[SciPy-user] swig and numpy.i
Jaonary Rabarisoa
jaonary at gmail.com
Thu Oct 11 03:57:45 EDT 2007
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
%{
#define SWIG_FILE_WITH_INIT
#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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20071011/90036e78/attachment.html>
More information about the SciPy-User
mailing list