[Numpy-discussion] Revised NEP-18, array_function protocol (original) (raw)

Hameer Abbasi einstein.edison at gmail.com
Sat Jun 30 10:40:29 EDT 2018


Hi Marten,

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 few drawbacks:

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. Something like:

def array_generation_function(func): @functools.wraps(func) 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)

        if success:
            return result

    return func(*args, **kwargs)

return wrapped

Hameer Abbasi -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20180630/3b707b80/attachment.html>



More information about the NumPy-Discussion mailing list