[Numpy-discussion] Array Interface
oliphant at ee.byu.edu
Thu Jun 8 17:22:47 CDT 2006
Thanks for the continuing discussion on the array interface.
I'm thinking about this right now, because I just spent several hours
trying to figure out if it is possible to add additional
"object-behavior" pointers to a type by creating a metatype that
sub-types from the Python PyType_Type (this is the object that has all
the function pointers to implement mapping behavior, buffer behavior,
etc.). I found some emails from 2002 where Guido indicates that it is
not possible to sub-type the PyType_Type object and add new function
pointers at the end without major re-writing of Python.
The suggested mechanism is to add a CObject to the tp_dict of the type
object itself. As far as I can tell is equivalent to what we are doing
with adding the array interface as an attribute look-up.
In trying to sell the array interface to the wider Python community (and
get it into Python 2.6), we need to simplify the interface though. I
no longer think having all of these attributes off the object itself is
a good idea (I think this is a case where flat *is not* better than nested).
It turns out that the __array_struct__ interface is the really important
one (it's the one that numarray, NumPy, and Numeric are all using). So,
one approach is to simply toss out support for the other part of the
interface in NumPy and "let it die."
Is this what people who opposing using the __array_struct__ attribute in
a dualistic way are suggesting? Clearly some of the attributes will
need to survive (like __array_descr__ which gives information that
__array_struct__ doesn't even provide). A big part of the push for
multidimensional arrays in Python is the addition of the PyArray_Descr *
object into Python (or something similar). This would allow a way to
describe data in a generic way and could change the use of
__array_descr__. But, currently the __array_struct__ attribute
approach does not support field-descriptions, so __array_descr__ is the
Please continue offering your suggestions...
More information about the Numpy-discussion