What is the canonical way of getting a numpy matrix as an argument to a C function which takes a double pointer?
Context: I'm using numpy
to validate some C code-to wit, I have a C function which takes a const double ** const
, and I'm using ctypes
to call the .so
from Python.
I've tried:
func.argtypes = ctypeslib.ndpointer(dtype=double, ndim=2, flags="C_CONTIGUOUS")
and passed the numpy
matrix directly (didn't work), as well as
func.argtypes = ctypes.POINTER(ctypes.POINTER(ctypes.c_double))
and then passed the numpy
matrix via various casts. Casting led to the Python error
TypeError: _type_ must have storage info
Note: This question came up a few years ago here, but there was no completely successful resolution.