[Biopython-dev] PATCH: NumPy support for BioPython

Michiel Jan Laurens de Hoon mdehoon at c2b2.columbia.edu
Fri Mar 9 15:22:48 EST 2007


Ed Schofield wrote:
>> Quick question:
>> The patch #includes numpy/oldnumeric.h for Python <--> C glue code that
>> uses Numeric. Why is this needed?
> 
> For the CONTIGUOUS and import_array() definitions right now.

For the CONTIGUOUS definition, there's a simpler solution.
CONTIGUOUS is currently only used in Bio/Cluster/clustermodule.h, and 
it's only used as follows:

PyArrayObject* array;
if (array->flags & CONTIGUOUS)...

Now, there is a macro in arrayobject.h, both in Numeric and in NumPy, 
that deals exactly with this situation:

In Numeric:
#define PyArray_ISCONTIGUOUS(m) ((m)->flags & CONTIGUOUS)

In numpy (imported via ndarrayobject.h):
#define PyArray_ISCONTIGUOUS(m) PyArray_CHKFLAGS(m, NPY_CONTIGUOUS)

So, if we use this macro instead of CONTIGUOUS directly, we can avoid 
using oldnumeric.h. Or am I missing something?

> I haven't yet got around to answering your question about import_array() ...
> ... because I don't know how the code generation works within NumPy.

Yeah I know, I don't think that code generation in NumPy was a good 
idea. It makes it too hard to figure out what is going on.

 > But I don't think extension modules will ever use NumPy's
> internal code generators; they just need the headers.

I think so too. NumPy itself actually calls import_array without 
#including oldnumeric.h. For example, see numpy/random/mtrand/mtrand.c. 
So we too should be fine without oldnumeric.h. But it might be good to 
check this with the NumPy folks.

--Michiel.


-- 
Michiel de Hoon
Center for Computational Biology and Bioinformatics
Columbia University
1130 St Nicholas Avenue
New York, NY 10032


More information about the Biopython-dev mailing list