[C++-sig] (David Abrahams)numpy.ndarray did not match PyArrayObject *
David Abrahams
dave at boost-consulting.com
Wed Sep 27 17:12:04 CEST 2006
Philip Austin <paustin at eos.ubc.ca> writes:
> so instead of getting PyArray_Type directly, as in the noddy
> example in boost_1_33_1/libs/python/test/m1.cpp, it's provided by
> the line:
>
> #define PyArray_Type (*(PyTypeObject *)PyArray_API[2])
> which you get when you include __multiarray_api.h
>
> I think this indirection is causing problems for
> lvalue_from_pytype<extract_array_object, &PyArray_Type>();
> since I can't get this to work either.
Yeah, that would be a problem. lvalue_from_pytype needs a
compile-time constant for the Python type.
Something like this will work, though:
//
// untested
//
void* extract_pyarray(PyObject* x)
{
return PyObject_TypeCheck(x, &PyArray_Type) ? x : 0;
}
BOOST_PYTHON_MODULE( /*your module name here*/ )
{
boost::python::converter::registry::insert(
&extract_pyarray, type_id<PyArrayObject>());
}
HTH,
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list