Dylan,

The error appears to be in example.c, not example_wrap.c.  The way you have 
written it, I think it should be double **x0.

But the SWIG typemaps require double*.

You could write it with double *x0, but then index with x0[i*m+j].

Or, if you want the [i][j] indexing, you could write a wrapper function with 
double *x1 that calls your matrix_example() function with &x1.  And then wrap 
the wrapper function.

-Bill

On Sep 4, 2012, at 5:18 PM, Dylan Temple wrote:

> Hello,
> 
> I am trying to use numpy.i to move a function from python to C that takes a 
> 2-D array as an input and am having difficulty.  The code is pretty long so 
> I've made a simple example that recreates the error.
> 
> example.c:
> 
> #include <stdio.h>
> #include "example.h"
> 
> void matrix_example (int n, int m, double *x0, \
>                                  int p, double *x)
> {
>       int i;
>       int j;
>       int k;
>       for (i = 0; i < n; ++i) {
>               for (j=0; j < 0; ++j) {
>                       x[k] = 2 * x0[i][j];
>                       ++k;
>               }
>       }
> }
> 
> example.h:
> 
> void matrix_example (int n, int m, double *x0, int p, double *x);
> 
> example.i:
> 
> %module example
> 
> %{
> #define SWIG_FILE_WITH_INIT
> #include "example.h"
> %}
> 
> %include "numpy.i"
> 
> %init %{
>       import_array();
> %}
> 
> %apply (int DIM1, int DIM2, double *IN_ARRAY2) {(int n, int m, double *x0)};
> %apply (int DIM1, double *ARGOUT_ARRAY1) {(int p, double *x)};
> 
> I then use prompts:
> 
> $ swig -python example.i
> $ python setup.py build_ext --inplace
> 
> However I get the error:
> example.c: In function ‘matrix_example’:
> example.c:12: error: subscripted value is neither array nor pointer
> error: command 'gcc' failed with exit status 1
> 
> It seems as though x0 is not actually being passed to the function as a 2-D 
> array.  Any help on why this error is happening would be great!
> 
> 
> Thank you,
> Dylan Temple
> 
> -- 
> Dylan Temple
> Graduate Student, University of Michigan NA&ME Department
> B.E. Naval Architecture
> M.S.E Naval Architecture
> 121 NA&ME Department, 2600 Draper Dr.
> 607-592-1749
> 
> _______________________________________________
> NumPy-Discussion mailing list
> [email protected]
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

** Bill Spotz                                              **
** Sandia National Laboratories  Voice: (505)845-0170      **
** P.O. Box 5800                 Fax:   (505)284-0154      **
** Albuquerque, NM 87185-0370    Email: [email protected] **


_______________________________________________
NumPy-Discussion mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to