[Numpy-discussion] Pass 2d ndarray into C **double using ctypes

Sturla Molden sturla.molden at gmail.com
Thu Jan 1 13:35:58 EST 2015


On 01/01/15 19:30, Sturla Molden wrote:
> You can pretend double** is an array of dtype np.intp. This is because
> on all modern systems, double** has the size of void*, and np.intp is an
> integer with the size of void* (np.intp maps to Py_intptr_t).

Well, it also requires that the user space is the lower half of the 
address space, which is usually true.

But to be safe against this you should use np.uintp instead of np.intp:

xpp = (x.__array_interface__['data'][0]
     + np.arange(x.shape[0])*x.strides[0]).astype(np.uintp)

doublepp = np.ctypeslib.ndpointer(dtype=np.uintp)



Sturla




More information about the NumPy-Discussion mailing list