[Numpy-discussion] Array Protocol change for Python 2.6 (original) (raw)

David M. Cooke cookedm at physics.mcmaster.ca
Fri Jun 9 19:30:57 EDT 2006


On Fri, 09 Jun 2006 16:03:32 -0700 Andrew Straw <strawman at astraw.com> wrote:

Tim Hochberg wrote:

>Which of the following should we require for an object to be "supporting >the array interface"? Here a producer is something that supplies >arraystruct or arrayinterface (where the latter is the Python level >version of the former as per recent messages). Consumers do something >with the results. > > 1. Producers can supply either arraystruct (if implemented in C) or > arrayinterface (if implemented in Python). Consumers must accept > both. > 2. Producers must supply both arraystruct and arrayinterface. > Consumers may accept either. > 3. Producers most supply both arraystruct and arrayinterface. > Consumers must accept both as well. > > I haven't been following as closely as I could, but is the following a possibility? 4. Producers can supply either arraystruct or arrayinterface. Consumers may accept either. The intermediate is a small, standalone (does not depend on NumPy) extension module that does automatic translation if necessary by provides 2 functions: asarraystruct() (which returns a CObject) and asarrayinterface() (which returns a tuple/dict/whatever).

For something to go in the Python standard library this is certainly possible. Heck, if it's in the standard library we can have one attribute which is a special ArrayInterface object, which can be queried from both Python and C efficiently.

For something like numpy (where we don't require a special object: the "producer" and "consumers" in Tim's terminology could be Numeric and numarray, for instance), we don't want a 3rd-party dependence. There's one case that I mentioned in another email:

  1. Producers must supply array_interface, and may supply array_struct. Consumers can use either.

Requiring array_struct means that Python-only modules can't play along, so I think it should be optional (of course, if you're concerned about speed, you would provide it).

Or maybe we should revisit the "no external dependencies". Perhaps one module would make everything easier, with helper functions and consistent handling of special cases. Packages wouldn't need it if they don't interact: you could conditionally import it when array_interface is requested, and fail if you don't have it. It would just be required if you want to do sharing.

-- |>|/|< /--------------------------------------------------------------------------
|David M. Cooke http://arbutus.physics.mcmaster.ca/dmc/ |cookedm at physics.mcmaster.ca



More information about the NumPy-Discussion mailing list