From: Francesc A. <fa...@op...> - 2003-01-15 20:24:22
|
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 ca= n > 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 requ= ires) PyArrayObject* NA OutputArray(PyObject *numarray, NumarrayType t, int=20 requires) PyArrayObject* NA IoArray(PyObject *numarray, NumarrayType t, int require= s) 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 parameter. In fact, I'm using the InputArray in PyTables to manage both numarray and Numeric arrays with good results. --=20 Francesc Alted |