1 Aug 03:23 2011

### Re: Help Calling C functions with 1d & 2d arrays?

Shalom Rav <csharpplusproject <at> gmail.com>

2011-08-01 01:23:15 GMT

2011-08-01 01:23:15 GMT

Thanks Robert. On Jul 30, 2:46 am, Robert Bradshaw <rober... <at> math.washington.edu> wrote: > On Fri, Jul 29, 2011 at 7:32 AM, Shalom Rav <csharpplusproj... <at> gmail.com> wrote: > > Blair, > > > Thank your for your detailed response. > > > I am just curious, were you able to compile my examples using the > > `c99` standard (gcc -std=c99 myFile.c -o myFile) ? > > > Also, is there a provide a python wrapper for the matrix prototype, > > just using a 2d numpy array and without using malloc etc? > > > Can this work, or will this cause issues: > > > def SumMatrixPython( numpy.ndarray[numpy.float32_t, ndim = 2] > > incomingArray ): > > # invoke the c function > > return SumMatrix(incomingArray.shape[0], incomingArray.shape[1], > > <float(Continue reading)**≥ incomingArray.data ) > > That won't work--data in a NumPy array is always 1-dimensional with > stride and dimension metadata used to index into it into a > multi-dimensional manner. Casting incomingArray.data to a float**will > be the same result as ((float*) (float value))[index]--probably a > segfault and certainly not what you want. > > Another way at getting at the rows is &incomingArray[i,0]--let Cython