View previous topic :: View next topic |
Author |
Message |
nyk Guru
Joined: 28 Aug 2004 Posts: 527 Location: Bern (Switzerland)
|
Posted: Thu Mar 22, 2007 2:31 pm Post subject: SWIG update breaks passing float** from python to C |
|
|
I wrote a python module of C code using SWIG.
It works perfectly with swig 1.3.21, but not anymore with 1.3.25 or 1.3.31.
This is the C function being called looks like:
Code: |
int *train(float **InVec, long nIV, long mIV, long maxcyc,int dim1,int dim2,float learnrate) {
// C code here, but not relevant for the error
}
|
This is the corresponding .i (swig) file: Code: |
%module foo
%include "carrays.i"
%array_class(int, intArray);
%{
int *train(float **InVec,long nIV,long mIV,long maxcyc,int dim1,int dim2,float learnrate);
%}
int *train(float **InVec,long nIV,long mIV,long maxcyc,int dim1,int dim2,float learnrate);
|
And this is how it's called from python: Code: |
import NumPtr,Numeric,foo
s,p,c,d1,d2,lr=10,10,100,10,10,0.1 # for example...
InVec=Numeric.zeros((s,p),Numeric.Float32) # org/pfam
# fill in some data here...
vP=NumPtr.getpointer(InVec) # Pointer to the 2D array
RetPt=kohonet.train(vP,s,p,c,d1,d2,lr) # Run C function
|
With swig 1.3.21 it works, but with 1.3.25, I get this unexplainable error:
Code: |
Traceback (most recent call last):
...
RetPt=foo.train(vP,samps,inps,samps2,cycs,d1,d2,lr) # Run C function
TypeError: argument number 1: a 'float **' is expected, 'str(_205dae0000000000_p_p_float)' is received
|
This is the error with 1.3.31: Code: |
Traceback (most recent call last):
...
RetPt=foo.train(vP,samps,inps,samps2,cycs,d1,d2,lr) # Run C function
TypeError: in method 'train', argument 1 of type 'float **
|
Is this a bug in newer versions of SWIG, or am I doing something in a wrong way? |
|
Back to top |
|
|
alex.blackbit Advocate
Joined: 26 Jul 2005 Posts: 2397
|
Posted: Fri Mar 23, 2007 12:21 am Post subject: |
|
|
i do not know what this 'str{....' thing means, but it does not really look like a pointer (address), or does it? |
|
Back to top |
|
|
nyk Guru
Joined: 28 Aug 2004 Posts: 527 Location: Bern (Switzerland)
|
Posted: Mon Mar 26, 2007 5:24 pm Post subject: |
|
|
What exactly do you mean? Is the following line in the SWIG interface not possible anymore in more recent versions of swig?
Code: |
%{
int *train(float **InVec,long nIV,long mIV,long maxcyc,int dim1,int dim2,float learnrate);
%}
|
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|