3

I have C code that I am currently incorporating into Python using Cython. The C code deals with 2D arrays in pointer to pointer format i.e. allocating memory for a 3x3 array is done as follows

float **A = (float **)malloc(3*sizeof(float *));
for (i=0; i<3; i++) A[i] = (float *)malloc(3*sizeof(float));

I am following this tutorial from the Cython Github wiki. Note that they store the 2D array linearly.

My question then is, what is the most efficient way to change the Cython code (specifically the handling of the Numpy array) so that it would work for a function void c_multiply (float** array, float multiplier, int m, int n) say (i.e. now dealing with pointer to pointer arrays).

Note I am currently handling it by having two converting functions in the C code that gets called initially and at the end to change the indexing from linear to pointer to pointer and vice versa. However, ideally I don't want to have to change the C code.

rwolst
  • 12,904
  • 16
  • 54
  • 75

0 Answers0