Stuck on accessing numpy.ndarray in c extension
Dear *All *I got stuck on it on wrapping c++ code which need accept numpy.ndarray as argument. The numpy.version I am using is '1.0rc1'.* *(My previous question is too massy, so I revised it. Sorry if I borthered you!) I used two ways to access numpy.ndarray, but they all reported error. ----------------------------------------------------------------------------------- 1st way: void testArray(PyArrayObject * args) { }
hello.testArray(b) Traceback (most recent call last): File "<stdin>", line 1, in ? Boost.Python.ArgumentError: Python argument types in hello.testArray(numpy.ndarray) did not match C++ signature: testArray(PyArrayObject*)
2nd way: void testArray(PyObject * args) { PyObject *input; PyArrayObject *array; if (!PyArg_ParseTuple(args, "O", &input)) printf("getting input failed!\n"); else printf("getting input sucess!\n"); }
import hello import numpy c = numpy.arange(25).reshape((5,5)) d = hello.testArray(c); getting input failed! d SystemError: new style getargs format but argument is not a tuple
Any suggestion will be appreciated. Thanks! -- Qinfeng(Javen) Shi Research School of Information Sciences and Engineering Australian National University Locked Bag 8001 Canberra ACT 2601
On Monday, 25. September 2006 09:30, Qinfeng(Javen) Shi wrote:
I used two ways to access numpy.ndarray, but they all reported error. .. both ways look OK, but you only provided the raw functions, not the exporting code. You should post the boost::python exporting code, too.
Traceback (most recent call last): File "<stdin>", line 1, in ? Boost.Python.ArgumentError: Python argument types in hello.testArray(numpy.ndarray) did not match C++ signature: testArray(PyArrayObject*) To me, that looks like a missing (lvalue) converter.
SystemError: new style getargs format but argument is not a tuple Are you using raw_function for the export? Otherwise, it naturally expects a tuple "args" with the array as first member. -> hello.testArray((c,))
-- Ciao, / / /--/ / / ANS
participants (2)
-
Hans Meine -
Qinfeng(Javen) Shi