summaryrefslogtreecommitdiff
path: root/numpy/lib/index_tricks.py
diff options
context:
space:
mode:
authorStephan Hoyer <shoyer@google.com>2018-10-08 12:52:55 -0700
committerStephan Hoyer <shoyer@google.com>2018-10-08 12:52:55 -0700
commit4141e24fc201f8cf76180ca69eaa2d89eafaee58 (patch)
tree3ee2de98a23d2972c9894332cddd9ee0969dc0ad /numpy/lib/index_tricks.py
parent2f4bc6f1d561230e9e295ce0d49fef5c4deb7ea0 (diff)
downloadnumpy-4141e24fc201f8cf76180ca69eaa2d89eafaee58.tar.gz
ENH: __array_function__ for np.lib, part 1
np.lib.arraypad through np.lib.nanfunctions
Diffstat (limited to 'numpy/lib/index_tricks.py')
-rw-r--r--numpy/lib/index_tricks.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/numpy/lib/index_tricks.py b/numpy/lib/index_tricks.py
index 009e6d229..06bb54bc1 100644
--- a/numpy/lib/index_tricks.py
+++ b/numpy/lib/index_tricks.py
@@ -13,6 +13,7 @@ from . import function_base
import numpy.matrixlib as matrixlib
from .function_base import diff
from numpy.core.multiarray import ravel_multi_index, unravel_index
+from numpy.core.overrides import array_function_dispatch
from numpy.lib.stride_tricks import as_strided
@@ -23,6 +24,11 @@ __all__ = [
]
+def _ix__dispatcher(*args):
+ return args
+
+
+@array_function_dispatch(_ix__dispatcher)
def ix_(*args):
"""
Construct an open mesh from multiple sequences.
@@ -729,6 +735,12 @@ s_ = IndexExpression(maketuple=False)
# The following functions complement those in twodim_base, but are
# applicable to N-dimensions.
+
+def _fill_diagonal_dispatcher(a, val, wrap=None):
+ return (a,)
+
+
+@array_function_dispatch(_fill_diagonal_dispatcher)
def fill_diagonal(a, val, wrap=False):
"""Fill the main diagonal of the given array of any dimensionality.
@@ -911,6 +923,11 @@ def diag_indices(n, ndim=2):
return (idx,) * ndim
+def _diag_indices_from(arr):
+ return (arr,)
+
+
+@array_function_dispatch(_diag_indices_from)
def diag_indices_from(arr):
"""
Return the indices to access the main diagonal of an n-dimensional array.