
Does someone have an example of using SWIG to connect Numeric arrays to C code that expects double* arguments?

"Paul F. Dubois" wrote:
Does someone have an example of using SWIG to connect Numeric arrays to C code that expects double* arguments?
Hi Paul, I have a fairly comprehensive set of typedefs (including 1-D and 2-D array input and output) for interfacing Numeric arrays here: ftp://cfa-ftp.harvard.edu/pub/ransom/numpy.i As an example, say you have a function with a prototype: int foo(double *array, int len_array); You would simply make a ".i" file with the following: ====================== %module foo %include numpy.i %apply double* IN_1D_DOUBLE { double *array }; int bar(double *array, int len_array); ======================= Run swig on it, compile it, and import it. Hope this helps, Scott -- Scott M. Ransom Address: Harvard-Smithsonian CfA Phone: (617) 496-7908 60 Garden St. MS 10 email: ransom@cfa.harvard.edu Cambridge, MA 02138 GPG Fingerprint: 06A9 9553 78BE 16DB 407B FFCA 9BFA B6FF FFD3 2989
participants (2)
-
Paul F. Dubois
-
Scott Ransom