From 781d8551a062e85a5097f4cde3e593736c82174e Mon Sep 17 00:00:00 2001 From: Stephan Hoyer Date: Thu, 20 Sep 2018 19:02:01 -0700 Subject: ENH: initial implementation of core __array_function__ machinery I'd like to implement NEP-18 in a multi-step process: 1. (This PR) Pure Python implementation of `__array_function__` machinery, based on the prototype implementation from NEP-18. 2. Rewrite this machinery in C as needed to improve performance. 3. Implement overrides on NumPy functions. Steps 2 and 3 should be able to happen in parallel (and with other people contributing!). This PR still needs more tests, especially for `ndarray.__array_function__` --- numpy/core/_methods.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'numpy/core/_methods.py') diff --git a/numpy/core/_methods.py b/numpy/core/_methods.py index 33f6d01a8..f49f64feb 100644 --- a/numpy/core/_methods.py +++ b/numpy/core/_methods.py @@ -154,3 +154,15 @@ def _ptp(a, axis=None, out=None, keepdims=False): umr_minimum(a, axis, None, None, keepdims), out ) + +def _array_function(self, func, types, args, kwargs): + # TODO: rewrite this in C + # Cannot handle items that have __array_function__ other than our own. + for t in types: + if (hasattr(t, '__array_function__') and + t.__array_function__ is not mu.ndarray.__array_function__): + return NotImplemented + + # Arguments contain no overrides, so we can safely call the + # overloaded function again. + return func(*args, **kwargs) -- cgit v1.2.1