Ok for everyone that might face the same problem as I did, here is how I finally solved it.
First I changed the header in the .h
file and the .c
file of the function from
void Flame_SetDataMatrix( Flame *self, float *data[], int N, int M, int T );
to
void Flame_SetDataMatrix( Flame *self, float *data, int N, int M, int T );
After that, I added
%apply (float* IN_ARRAY2, int DIM1, int DIM2) {
(float *data, int N, int M)
};
To the interface file (flame.i
). This makes it possible to call the function in Python like this: flame.Flame_SetDataMatrix( flameobject, data, T)
, where data is a numpy array with two dimensions.
The "problem" now is that the array that arrives in the C function is in the wrong format, because we want a double array (which in this case is a pointer to a pointer to a float).
The solution is to convert this array, which is wrapped in a single dimension, to reconstruct the double array in the c code like this:
//n = number of rows, m= number of columns columns
void Flame_SetDataMatrix( Flame *self, float *data, int n, int m, int dt )
{
//convert data to float** for later use
int i=0, j=0;
float ** data2 = (float**) calloc( n, sizeof(float*) );
for (i=0; i<n; i++){
data2[i] = calloc( m, sizeof(float) );
for (j=0; j<m; j++){
//the data is in a single array row after row, so i*columns+j
data2[i][j] = data[i * m + j];
}
}
In the end I could use the same "trick" to also get a two dimensional float array back into a numpy array, which I did have to reschape but in numpy that is easy.
Hope it will help someone.