[Numpy-discussion] is __array_ufunc__ ready for prime-time?

Stephan Hoyer shoyer at gmail.com
Tue Nov 7 17:01:53 EST 2017

On Tue, Nov 7, 2017 at 12:23 PM Chris Barker <chris.barker at noaa.gov> wrote:

> And then a third abc for indexing support, although, I am not sure how
>> that could get implemented...
> This is the really tricky one -- all ABCs really check is the existence of
> methods -- making sure they behave the same way is up to the developer of
> the ducktype.
> which is K, but will require discipline.
> But indexing, specifically fancy indexing, is another matter -- I'm not
> sure if there even a way with an ABC to check for what types of indexing
> are support, but we'd still have the problem with whether the semantics are
> the same!
> For example, I work with netcdf variable objects, which are partly
> duck-typed as ndarrays, but I think n-dimensional fancy indexing works
> differently... how in the world do you detect that with an ABC???

We recently worked out a hierarchy of indexing types for xarray. To a crude
approximation, we have:
- "Basic" indexing support for slices and integers. Nearly every array type
satisfies this.
- "Outer" or "orthogonal" indexing with slices, integers and 1D arrays.
This is what netCDF4-Python and Fortran/MATLAB support.
- "Vectorized" indexing with broadcasting and multi-dimensional indexers.
NumPy supports a generalization of this, but I would not wish the edge
cases involving mixed slices/arrays upon anyone.
- "Logical" indexing by a boolean array with the same shape.
- "Exactly like NumPy" for subclasses or wrappers around NumPy arrays.

There's some ambiguities in this, but that's what specs are for. For most
applications, we probably don't need most of these: ABCs for "Basic",
"Logical" and "Exactly like NumPy" would go a long ways.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20171107/55fe372d/attachment.html>

More information about the NumPy-Discussion mailing list