ctypes problem
Ben Willmore <[email protected]> Fri, 2 Sep 2011 11:37:23 +0100
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <[email protected]> |
Can anyone tell me why the Python code below is not equivalent to the C code? The Python code fails (returning None), where the C code correctly returns a pointer. As far as I can see, they should be identical.
Many thanks,
Ben
----------------------------- python version
import ctypes
from numpy import ctypeslib
import numpy as np
f = ctypes.cdll.LoadLibrary('/usr/local/lib/libfftw3.3.dylib')
rank = 2
n = np.array([5,5])
howmany = 1
inp = np.random.rand(10,10)+0.j
inembed = n
istride = 1
idist = 0
out = np.random.rand(10,10)+0.j
onembed = n
ostride = 1
odist = 0
sign = -1
flags = 0
##
f.fftw_plan_many_dft.argtypes = [ctypes.c_int, # rank
ctypeslib.ndpointer(dtype=int, ndim=1, # n
flags='contiguous,aligned'),
ctypes.c_int, # howmany
ctypeslib.ndpointer(dtype='complex128', # in
flags='aligned,writeable'),
ctypeslib.ndpointer(dtype=int, ndim=1, # inembed
flags='contiguous,aligned'),
ctypes.c_int, # istride
ctypes.c_int, # idist
ctypeslib.ndpointer(dtype='complex128', # out
flags='aligned,writeable'),
ctypeslib.ndpointer(dtype=int, ndim=1, # onembed
flags='contiguous,aligned'),
ctypes.c_int, # ostride
ctypes.c_int, # odist
ctypes.c_int, # sign
ctypes.c_uint] # flags
f.fftw_plan_many_dft.restype = ctypes.c_void_p
##
p = f.fftw_plan_many_dft(rank, n, howmany, inp, inembed, istride, idist,
out, onembed, ostride, odist, sign, flags)
print p
--------------------------- C version
#include <fftw3.h>
#include <stdio.h>
main()
{
int rank = 2;
int n[2] = {5, 5};
int howmany = 1;
fftw_complex in[100];
int *inembed = n;
int istride = 1;
int idist = 0;
fftw_complex out[100];
int *onembed = n;
int ostride = 1;
int odist = 0;
int sign = -1;
unsigned flags = 0;
fftw_plan p;
p = fftw_plan_many_dft(rank, n, howmany, in, inembed, istride, idist,
out, onembed, ostride, odist, sign, flags);
printf("%p\n", p);
}
------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev