[Numpy-discussion] ctypes: how does load_library work ?
Stefan van der Walt
stefan at sun.ac.za
Fri Aug 18 04:16:46 CDT 2006
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
>
> _hello = cdll.LoadLibrary('libhello.so')
>
> _hello.sum.restype = c_int
> _hello.sum.artype = [POINTER(c_int), c_uint]
>
> def sum(data):
> return _hello.sum(data.ctypes.data_as(POINTER(c_int)), len(data))
>
> n = 10
> data = N.arange(n)
>
> print data
> print "sum(data) is " + str(sum(data))
>
>
> That works OK, but to avoid the platform dependency, I would like to use
> load_library from numpy: I just replace the cdll.LoadLibrary by :
>
> _hello = N.ctypeslib.load_library('hello', '.')
Shouldn't that be 'libhello'? Try
_hello = N.ctypes_load_library('libhello','__file__')
Cheers
Stéfan
More information about the Numpy-discussion
mailing list