Passing back an array from an extension module?

Chris Barker chrishbarker at home.net
Fri Jun 8 15:47:18 EDT 2001


Bob Greschke wrote:
> 
> Is this a job for NumPy?
> 
The sort answer is yes this would be pretty straighforward. See Chad
Everett's post.

> I have a C extension function that malloc()s an array of int32s, calls
> another C function which reads/decodes a file of data and fills in the
> array.

My big question is why you don't do the whole thing in NumPy? You may
not need the C code at all, unless the decoding is really wierd. Is it a
compression algorithm or something?

> I initially thought I could just create a tuple and pass
> that back, since nothing is going to be done with the values except to
> draw a graph, but there is the possibility of there being 16,000,000
> data points...that makes for a slightly large statement, doesn't it?

You could also use a list, rather than a tuple, but a NumPy array would
make much more sense. Oh, how I long for it to part of the standard
library.

> Now what about Py_DECREF, INCREF and all of that stuff in these
> situations?

You do have to be a bit careful about these, but what you want to do
sounds pretty straightforward.

-Chris




-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker at home.net                 ---           ---           ---
http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------



More information about the Python-list mailing list