| Version 2 (modified by oliphant, 7 years ago) |
|---|
This page is a launchpad for the array superclass design.
There is a PEP proposing essentially this superclass already in progress. It can be checked out and reviewed from SVN from
Below is Tim's formulation of a similar object which he constructed independently.
Tim Hochberg <tim.hochberg@…> wrote on numpy-discussion:
This may be an oportune time to propose something that's been cooking in
the back of my head for a week or so now: A stripped down array
superclass. The details of this are not at all locked down, but here's a
strawman proposal.
We add an array superclass. call it basearray, that has the same
C-structure as the existing ndarray. However, it has *no* methods or
attributes. It's simply a big blob of data. Functions that work on
the C structure of arrays (ufuncs, etc) would still work on this
arrays, as would asarray, so it could be converted to an ndarray as
necessary. In addition, we would supply a minimal set of functions
that would operate on this object. These functions would be chosen
so that the current array interface could be implemented on top of
them and the basearray object in pure python. These functions would
be things like set_shape(a, shape), etc. They would be segregated
off in their own namespace, not in the numpy core. [Note that I'm
not proposing we actually implement ndarray this way, just that we
make is possible]. This leads to several useful outcomes.
1. If we're careful, this could be the basic array object that
we propose, at least for the first roun,d for inclusion in the
Python core. It's not useful for anything but passing data betwen
various application that understand the data structure, but that in
itself could be a huge win. And the fact that it's dirt simple would
probably be an advantage to getting it into the core.
2. It provides a useful marker class. MA could inherit from it
(and use itself for it's data attribute) and then asanyarray would
behave properly. MA could also use this, or a subclass, as the mask
object preventing anyone from accidentally using it as data (they
could always use it on purpose with asarray).
3. It provides a platform for people to build other,
ndarray-like classes in Pure python. This is my main interest. I've
put together a thin shell over numpy that strips it down to it's
abolute essentials including a stripped down version of ndarray that
removes most of the methods. All of the __array_wrap__[1] stuff
works quite well most of the time, but there's still some issues
with being a subclass when this particular class is conceptually a
superclass. If we had an array superclass of some sort, I believe
that these would be resolved.
In principle at least, this shouldn't be that hard. I think it should
mostly be rearanging some code and adding some wrappers to existing
functions.
