diff options
author | Stephan Hoyer <shoyer@google.com> | 2018-09-20 19:02:01 -0700 |
---|---|---|
committer | Stephan Hoyer <shoyer@google.com> | 2018-09-20 19:09:47 -0700 |
commit | 781d8551a062e85a5097f4cde3e593736c82174e (patch) | |
tree | efa53a0d226a72f9a43e81f0ac70a2567ff86abf /numpy/core/_methods.py | |
parent | 7248c1d8ccfa3643a9286c46bd134b2e113ba85f (diff) | |
download | numpy-781d8551a062e85a5097f4cde3e593736c82174e.tar.gz |
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__`
Diffstat (limited to 'numpy/core/_methods.py')
-rw-r--r-- | numpy/core/_methods.py | 12 |
1 files changed, 12 insertions, 0 deletions
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) |