[f2py] f2py, C, and multidimensional arrays.
Daniel Welling
dantwelling at gmail.com
Sat May 29 08:41:52 EEST 2010
Greetings. I am new to F2py and am trying to use it to wrap some simple C
functions. I've had success with scalars and vectors, but cannot get any
multidimensional arrays to work correctly. An example:
/* bar.c */
void bar(int n, int m, double **x) {
int i, j;
for (i=0; i<n; i++)
for (j=0; j<m; j++)
printf("Position %i, %i = %.3f\n", i, j, x[i][j]);
}
! wrapper m.pyf
python module m
interface
subroutine bar(n, m, x)
intent(c) bar
intent(c)
integer intent() :: n
integer intent() :: m
double precision intent(in) :: x(n,m)
end subroutine bar
end interface
end python module m
Build shared object:
$ f2py2.5 foo.c foo.pyf -c
Try to run it:
>>>import m
>>>import numpy as np
>>>dog = np.zeros((0,0))
>>>m.bar(dog)
Bus error
And that's it. It drops me out of ipython/python shell and back to the bash
prompt. I cannot find any examples similar to this, nor any mailing list
threads on this topic. Does anyone have any experience with such examples?
Thanks for your help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cens.ioc.ee/pipermail/f2py-users/attachments/20100528/2f98fafe/attachment.htm
More information about the f2py-users
mailing list