[Numpy-discussion] Revised NEP-18, __array_function__ protocol
einstein.edison at gmail.com
Sat Jun 30 10:40:29 EDT 2018
Sorry, I had clearly misunderstood. It would indeed be nice for overrides
to work on functions like `zeros` or `arange` as well, but it seems strange
to change the signature just for that. As a possible alternative, should we
perhaps generally check for overrides on `dtype`?
While this very clearly makes sense for something like astropy, it has a
- Other duck arrays such as Dask need more information than just the
dtype. For example, Dask needs chunk sizes, XArray needs axis labels, and
pydata/sparse needs to know the type of the reference array in order to
make one of the same type. The information in a reference array is a strict
superset of information in the dtype.
- There’s a need for a separate protocol, which might be a lot harder to
work with for both NumPy and library authors.
- Some things, like numpy.random.RandomState, don’t accept a dtype
As for your concern about changing the signature, it’s easy enough with a
decorator. We’ll need a separate decorator for array generation functions.
def wrapped(*args, **kwargs, array_reference=np._NoValue):
if array_reference is not np._NoValue:
success, result = try_array_function_override(wrapped,
[array_reference], args, kwargs)
return func(*args, **kwargs)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion