From: Stefan v. d. W. <st...@su...> - 2006-08-18 09:17:09
|
On Fri, Aug 18, 2006 at 01:54:44PM +0900, David Cournapeau wrote: > import numpy as N > from ctypes import cdll, POINTER, c_int, c_uint >=20 > _hello =3D cdll.LoadLibrary('libhello.so') >=20 > _hello.sum.restype =3D c_int > _hello.sum.artype =3D [POINTER(c_int), c_uint] >=20 > def sum(data): > return _hello.sum(data.ctypes.data_as(POINTER(c_int)), len(data)) >=20 > n =3D 10 > data =3D N.arange(n) >=20 > print data > print "sum(data) is " + str(sum(data)) >=20 >=20 > That works OK, but to avoid the platform dependency, I would like to us= e=20 > load_library from numpy: I just replace the cdll.LoadLibrary by : >=20 > _hello =3D N.ctypeslib.load_library('hello', '.') Shouldn't that be 'libhello'? Try _hello =3D N.ctypes_load_library('libhello','__file__') Cheers St=E9fan |