[Numpy-discussion] Problem in swig

Bill Spotz wfspotz at sandia.gov
Thu May 20 11:18:44 EDT 2010


I tried the following:

%module example
%{
#define SWIG_FILE_WITH_INIT
//#include "example.h"
%}
%include "numpy.i"

%init %{
     import_array();
%}

%apply (float* INPLACE_ARRAY1, int DIM1) {(float *a, int na), (float  
*b, int nb)};

%inline
{
   void update_incident_field(int k, float *a, int na, float *b, int nb)
   {
     for (i=0; i<na; i ++)
     {
       a[i] = a[i] + b[i] * k;
     }
   }
}

$ swig -python example.i

and the resulting example_wrap.c file looks OK for me.  What strange  
output did you get?

On May 19, 2010, at 7:43 PM, Steven Nien wrote:

> I want to pass 1 integer and 2 numpy array into the C function as  
> followings:
>
> void update_incident_field(int k, float *a, int na, float *b, int  
> nb) {
> for (i=0; i<na; i ++) {
>     a[i] = a[i] + b[i] * k;
> }
> }
>
> But I don't know how to write the interface code (***.i)
> Can someone help me?
>
> Thanks!
>
> The swig interface code I written(did't work, strange output)
>
> %module example
> %{
> #define SWIG_FILE_WITH_INIT
> #include "example.h"
> %}
> %include "numpy.i"
>
> %init %{
>     import_array();
> %}
>
> %apply (float* INPLACE_ARRAY1, int DIM1) {(float *a, int na), (float  
> *b, int nb)};
>
> %include "example.h"
>
>
>
> <ATT00002.txt>

** Bill Spotz                                              **
** Sandia National Laboratories  Voice: (505)845-0170      **
** P.O. Box 5800                 Fax:   (505)284-0154      **
** Albuquerque, NM 87185-0370    Email: wfspotz at sandia.gov **









More information about the NumPy-Discussion mailing list