[SciPy-dev] C API

Robert Kern robert.kern at gmail.com
Thu Nov 24 01:17:52 CST 2005


Nariman Habili wrote:
> Hi there,
> 
> I would like to know how to extract a value (eg int) from a PyObject that 
> contains an ndarray. I'm using boost.python to expose classes to Python. I'm 
> passing an ndarray to C++ by reference. However, since boost.python hasn't 
> been updated yet to scipy core, I'm using the C API.
> I've tried PyArray_GETITEM, however it returns a PyObject, and I'm not sure 
> how to extract an int or double etc from it. I need the C types so I can 
> interface python with other parts of my code.

I'm not sure what you mean by "a PyObject that contains an ndarray." If,
on the other hand, you mean "a PyObject that *is* an ndarray," then it's
pretty easy. Read the file scipy/doc/CAPI.txt, specifically, the section
"Passing Data Type information to C-code".

> Would boost python be updated to scipy core soon?

You'll have to ask the boost.python developers about that. It shouldn't
be hard. The old Numeric C API still works. You just have to change

  #include "Numeric/arrayobject.h"

to

  #include "scipy/arrayobject.h"

They will probably want to do more, though, because the new API has
extended the old one in interesting ways.

-- 
Robert Kern
robert.kern at gmail.com

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter




More information about the Scipy-dev mailing list