[Numpy-discussion] Numpy array from ctypes pointer object?
theller at python.net
Wed Jul 12 14:15:13 CDT 2006
Mark Heslep schrieb:
> Travis Oliphant wrote:
>> Mark Heslep wrote:
>>> I don't see a clean way to create a numpy array from a ctypes pointer
>>> object. Is the __array_interface_ in ctypes the thing thats missing
>>> needed to make this happen? I've followed Albert's Scipy cookbook
>>> on ctypes here
>>> On the C side the PyArray_SimpleNewFromData( ..dimensions, ...data
>>> ptr) C API does the job nicely. Is there a ctypes paradigm for
>> Can you somehow call this function using ctypes?
> That might work, though indirectly. As I think I understand from ctypes
> docs: Ctypes uses functions exposed in a shared library, macros
> existing only a header are not available. If its PyArray... is a macro
> then I a) need to compile and make a little library directly from
> arrayobject.h or b) need to use the root function upon which the macro
> is based, PyArrayNew?
Sure, macros will not work.
> ctypes has built-in access to the functions in the core python library,
> but Im not sure which library contains all the PyArray API calls, since
> its all typically hidden by distutils and setup.py
On Linux it doesn't matter, since you don't need to know which library
exports a function (If I understand shared libs in Linux correctly).
At least dlsym can be called with a NULL handle.
On windows, functions can only be retrieved from exactly the library that
exposes them. Plus, the function must explicitly marked exported
either by compiler directives in the source code of by listing them
in a .def file.
More information about the Numpy-discussion