Thank you Rubin,
I know this example. The problem is that in the example they take 2
input arrays of the same size, and I want to have one input and other
output.
Something like testdot(double *ivec, double *ovec, int size);
I did this
/* to testtdot */
%apply (double *IN_ARRAY1, int DIM1) { (double *ivec, int isize)}
%apply (double *ARGOUT_ARRAY1, int DIM1) { (double *ovec, int osize)}
To declare the input and output arrays. After that I declared the inline
function as described
rename(testdot) my_testdot;
%inline %{
void my_testdot(double *ivec, double *ovec, int isize, int osize){
if (isize != osize){
PyErr_Format(PyExc_ValueError, "Arrays of lengths (%d,%d)
given",isize,osize);
exit(-1);
}
return testdot(ivec, ovec, isize);
}
%}
But it does not work: It says
NotImplementedError: Wrong number of arguments for overloaded function
'testdot'.
Possible C/C++ prototypes are:
my_testdot(double *,int,double *,int)
testdot(double *,double *,int)
Actually, I am starting to think that it is maybe better idea to use the
IN-place Arrays....
Thanks a lot!
Rubin, Jared wrote:
>
> Jose,
> The numpy.i file, that used to be distributed with numpy, but is now
> distributed with scipy has an example of what to do. It is towards the
> end of the document
> From your C declaration i am assuming that both invec and outvec are
> the same size
>
> (double *invec, double *outvec, int size);
>
> i found the document here
>
> www.aero.iitb.ac.in/~prabhu/tmp/python.../numpy_swig.pdf
>
> Look at the common example on pg 10
>
>
> Jared
>
>
> -----Original Message-----
> From:
swig-user-bounces@... on behalf of Jose Guzman
> Sent: Fri 7/3/2009 4:29 AM
> To:
Swig-user@...
> Subject: [Swig-user] To accept one 1D-Numpy array and return another
>
> Dear swig-user group!
>
> I am new to Swig and after a couple of successfully performed tests (the
> numpyi. pdf document helped a lot), I decided to create a "simple"
> function which receives a 1D NumPy array and returns ANOTHER. The simple
> question is... is there any way to create a function which accept a
> vector and returns another vector?
>
> something like
> >>>mymodule.myfunc(inputarray)
> >>> array([ 20.25, 12.25, 6.25, 2.25, 0.25, 0.25, 2.25,
> 6.25, 12.25, 20.25])
>
>
> The only solution I found was the following.
>
>
> My C function is defined as follows:
>
> void sse(double *vec, int n); // actually I wanted to use void sse
> (double *invec, double *outvec, int size);
>
> Then I use In-Place arrays:
>
> %apply (double *INPLACE_ARRAY1, int DIM1) { (double *vec, int n)}
>
> and modify the function to receive only one array which is gonna be
> transformed. After that I modified my function
>
> %pythoncode{
>
> def ssem(list):
> a = np.array(list,dtype=float)
> sse(a)
> return a
> }
>
> Now I have only to use ssem in stead of sse. :(
>
> Is there any better/simple way to do it?
>
> Thanks a lot in advance!!!
>
> Jose.
>
>
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> Swig-user mailing list
>
Swig-user@...
>
https://lists.sourceforge.net/lists/listinfo/swig-user>
Thank you Rubin,
I know this example. The problem is that in the example they take 2
input arrays of the same size, and I want to have one input and other
output.
Something like testdot(double *ivec, double *ovec, int size);
I did this
/* to testtdot */
%apply (double *IN_ARRAY1, int DIM1) { (double *ivec, int isize)}
%apply (double *ARGOUT_ARRAY1, int DIM1) { (double *ovec, int osize)}
To declare the input and output arrays. After that I declared the inline
function as described
rename(testdot) my_testdot;
%inline %{
void my_testdot(double *ivec, double *ovec, int isize, int osize){
if (isize != osize){
PyErr_Format(PyExc_ValueError, "Arrays of lengths (%d,%d)
given",isize,osize);
exit(-1);
}
return testdot(ivec, ovec, isize);
}
%}
But it does not work: It says
NotImplementedError: Wrong number of arguments for overloaded function
'testdot'.
Possible C/C++ prototypes are:
my_testdot(double *,int,double *,int)
testdot(double *,double *,int)
Actually, I am starting to think that it is maybe better idea to use the
IN-place Arrays....
Thanks a lot!
Rubin, Jared wrote:
>
> Jose,
> The numpy.i file, that used to be distributed with numpy, but is now
> distributed with scipy has an example of what to do. It is towards the
> end of the document
> From your C declaration i am assuming that both invec and outvec are
> the same size
>
> (double *invec, double *outvec, int size);
>
> i found the document here
>
> www.aero.iitb.ac.in/~prabhu/tmp/python.../numpy_swig.pdf
>
> Look at the common example on pg 10
>
>
> Jared
>
>
> -----Original Message-----
> From:
swig-user-bounces@... on behalf of Jose Guzman
> Sent: Fri 7/3/2009 4:29 AM
> To:
Swig-user@...
> Subject: [Swig-user] To accept one 1D-Numpy array and return another
>
> Dear swig-user group!
>
> I am new to Swig and after a couple of successfully performed tests (the
> numpyi. pdf document helped a lot), I decided to create a "simple"
> function which receives a 1D NumPy array and returns ANOTHER. The simple
> question is... is there any way to create a function which accept a
> vector and returns another vector?
>
> something like
> >>>mymodule.myfunc(inputarray)
> >>> array([ 20.25, 12.25, 6.25, 2.25, 0.25, 0.25, 2.25,
> 6.25, 12.25, 20.25])
>
>
> The only solution I found was the following.
>
>
> My C function is defined as follows:
>
> void sse(double *vec, int n); // actually I wanted to use void sse
> (double *invec, double *outvec, int size);
>
> Then I use In-Place arrays:
>
> %apply (double *INPLACE_ARRAY1, int DIM1) { (double *vec, int n)}
>
> and modify the function to receive only one array which is gonna be
> transformed. After that I modified my function
>
> %pythoncode{
>
> def ssem(list):
> a = np.array(list,dtype=float)
> sse(a)
> return a
> }
>
> Now I have only to use ssem in stead of sse. :(
>
> Is there any better/simple way to do it?
>
> Thanks a lot in advance!!!
>
> Jose.
>
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Swig-user mailing list
>
Swig-user@...
>
https://lists.sourceforge.net/lists/listinfo/swig-user>
------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user