[Numpy-discussion] swig + numpy + variable length arrays

Andrew Nelson andyfaff@gmail....
Mon Jul 16 04:30:14 CDT 2012

Dear list,
I am trying to SWIG a C function with the signature:

void abelescalcall(long numcoefs, double *coefP, long npoints , double
*yP, double *xP);

numcoefs corresponds to the number of points in the coefP array.
npoints corresponds to the number of points in yP and xP arrays.

coefP and xP are inputs (IN_ARRAY1), yP is an output (ARGOUT_ARRAY1).

I have been trying to use the following input file:

%module reflect

    #include "myfitfunctions.h"

%include "numpy.i"

%init %{

%apply (long DIM1, double* IN_ARRAY1){(long numcoefs, double* coefP)}
%apply (long DIM1, double* ARGOUT_ARRAY1){(long len2, double* yP)}
%apply (long DIM1, double* IN_ARRAY1){(long len3, double *xP)}
%include "myfitfunctions.h"
%rename (abelescalcall) my_abeles;

%inline %{
my_abeles(long numcoefs, double* coefP, long len2, double* yP, long
len3, double *xP) {
	if (len2 != len3) {
        PyErr_Format(PyExc_ValueError, "Arrays of lengths (%d,%d)
given", len2, len3);
        return 0.0;
	abelescalcall(numcoefs, coefP, len2, yP, xP);

However, if I look at the wrapper code, and if I try to call
my_abeles, then I am asked for 6 parameters. I only want to supply two
numpy arrays - coefP and xP.

thanks for any help you are able to give. (I spent the whole afternoon
trying to get this bloomin thing to work).


Dr. Andrew Nelson


More information about the NumPy-Discussion mailing list