[Numpy-discussion] Optionally using Numeric in another compiled extension package.

Francesc Alted falted at openlc.org
Wed Jan 15 12:25:27 EST 2003

A Dimecres 15 Gener 2003 21:16, Todd Miller va escriure:
> My idea to couple these was "not good".  They're not compatible at that
> level anyway.
> Since numarray and Numeric are only source level compatible,  C-code can
> be compiled to work with one or the other,  but not both at the same
> time.  It probably makes more sense to just implement for Numeric.  If
> you do want to implement for both,  treat them as seperate cases with
> seperate recognizer functions and element access code.
> But...  It's not clear to me that knowing an object is an array will
> help since getting data elements still has to be done fast,  and that
> seems hard to do without knowing the arrayobject struct.   Keep in mind
> that Numeric and numarray arrays are strided and possibly discontiguous,
>  so there's more to data access than owning a base pointer, as would be
> the case in C.

I think you can use the numarray High-Level C API to overcome these
dificulties. For example, by using the calls:

PyArrayObject* NA InputArray(PyObject *numarray, NumarrayType t, int requires)
PyArrayObject* NA OutputArray(PyObject *numarray, NumarrayType t, int 
PyArrayObject* NA IoArray(PyObject *numarray, NumarrayType t, int requires)

as documented in the User's Guide, you can get well-behaved (i.e.
contiguous and well-aligned) C arrays (copying them, if needed) from both
numarray or Numeric arrays if you pass C_ARRAY as the value for requires

In fact, I'm using the InputArray in PyTables to manage both numarray and
Numeric arrays with good results.

Francesc Alted

More information about the NumPy-Discussion mailing list