Hello,<div><br></div><div>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.</div>
<div><br></div><div>example.c:</div><div><br></div><div><div>#include <stdio.h></div><div>#include "example.h"</div></div><div><br></div><div><div>void matrix_example (int n, int m, double *x0, \</div><div>
<span class="Apple-tab-span" style="white-space:pre">                         </span>   int p, double *x)</div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>int i;</div><div><span class="Apple-tab-span" style="white-space:pre">       </span>int j;</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>int k;</div><div><span class="Apple-tab-span" style="white-space:pre">       </span>for (i = 0; i < n; ++i) {</div><div><span class="Apple-tab-span" style="white-space:pre">         </span>for (j=0; j < 0; ++j) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                      </span>x[k] = 2 * x0[i][j];</div><div><span class="Apple-tab-span" style="white-space:pre">                 </span>++k;</div><div><span class="Apple-tab-span" style="white-space:pre">         </span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>}</div><div>}</div></div><div><br></div><div>example.h:</div><div><br></div><div>void matrix_example (int n, int m, double *x0, int p, double *x);</div><div>
<br></div><div>example.i:</div><div><br></div><div><div>%module example</div><div><br></div><div>%{</div><div>#define SWIG_FILE_WITH_INIT</div><div>#include "example.h"</div><div>%}</div><div><br></div><div>%include "numpy.i"</div>
<div><br></div><div>%init %{</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>import_array();</div><div>%}</div></div><div><br></div><div><div>%apply (int DIM1, int DIM2, double *IN_ARRAY2) {(int n, int m, double *x0)};</div>
<div>%apply (int DIM1, double *ARGOUT_ARRAY1) {(int p, double *x)};</div></div><div><br></div><div>I then use prompts:</div><div><br></div><div>$ swig -python example.i</div><div><div>$ python setup.py build_ext --inplace</div>
</div><div><br></div><div>However I get the error:</div><div><div>example.c: In function ‘matrix_example’:</div><div>example.c:12: error: subscripted value is neither array nor pointer</div><div>error: command 'gcc' failed with exit status 1</div>
</div><div><br></div><div>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!</div><div><br></div><div><br></div><div>Thank you,</div>
<div>Dylan Temple</div><div><br></div><div>-- <br>Dylan Temple<br>Graduate Student, University of Michigan NA&ME Department<br>B.E. Naval Architecture<br>M.S.E Naval Architecture<br>121 NA&ME Department, 2600 Draper Dr.<br>
607-592-1749<br><br>
</div>