Creating a python c-module: passing double arrays to c functions. segmentation fault. swig
sturlamolden
sturlamolden at yahoo.no
Sun Mar 30 16:56:53 EDT 2008
On 30 Mar, 22:21, kmg... at gmail.com wrote:
> Hello everybody,
>
> I'm building a python module to do some heavy computation in C (for
> dynamic time warp distance computation).
Why don't you just ctypes and NumPy arrays instead?
# double timewarp(double x[], int lenx, double y[], int leny);
import numpy
import ctypes
from numpy.ctypeslib import ndpointer
from ctypes import c_int
_timewarp = ctypes.cdll.timewarp.timewarp # timewarp.dll
array_pointer_t = ndpointer(dtype=double)
_timewarp.argtypes = [array_pointer_t, c_int, array_pointer_t, c_int]
def timewarp(x, y):
lenx, leny = x.shape[0], y.shape[0]
return _timewarp(x, lenx, y, leny)
More information about the Python-list
mailing list