[C++-sig] passing Numeric arrays as arguments

Greg Landrum greglandrum at earthlink.net
Thu Dec 12 02:10:22 CET 2002


[Boost 1.29, python 2.2.2,  g++ 3.2, RH8.0]

I've been trying to get a Numeric array object passed in as an argument to 
a function I've defined in a BPLv2 module, without much success.

At the moment I'm happy to get the object in as a PyArrayObject *, because 
I've got a bunch of code that is expecting those pointers.

Since I can't figure out how to extract a PyArrayObject * from a 
python::numeric::array (if that's even possible), I've attempted to define 
the following simple function:

PyObject *MatFunc(PyArrayObject *arg){
   PyObject *res = PyTuple_New(2);
   return res;
}

(eventually this will do more, I'm starting small)

but whenever I call this Python with a Numeric array as an argument, I get 
the dreaded catch-all "TypeError: bad argument type for built-in operation".

Am I wrong to be even attempting this?  Should I just give up and do a 
normal extension module?

-greg

----
greg Landrum (greglandrum at earthlink.net)
Software Carpenter/Computational Chemist





More information about the Cplusplus-sig mailing list