diff options
author | Matti Picus <matti.picus@gmail.com> | 2022-02-27 06:34:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-27 06:34:49 +0200 |
commit | 3b03c2ab12368561574a46f59c7e0992a36b896b (patch) | |
tree | c7067d3c550877d259dc4532998d067d40bcbc17 /numpy/lib/function_base.py | |
parent | 3f7d9d8f32d5ca472335ffcf501a0d3f67a9352f (diff) | |
parent | 3c81e3020a5b65c1590fc73a53ee9193a2c8b224 (diff) | |
download | numpy-3b03c2ab12368561574a46f59c7e0992a36b896b.tar.gz |
Merge pull request #16895 from DevinShanahan/delete-speedup
MAINT: extend delete single value optimization
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r-- | numpy/lib/function_base.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index f4296df2e..ff56196c3 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -5094,6 +5094,18 @@ def delete(arr, obj, axis=None): return new if isinstance(obj, (int, integer)) and not isinstance(obj, bool): + single_value = True + else: + single_value = False + _obj = obj + obj = np.asarray(obj) + if obj.size == 0 and not isinstance(_obj, np.ndarray): + obj = obj.astype(intp) + elif obj.size == 1 and not isinstance(_obj, bool): + obj = obj.astype(intp).reshape(()) + single_value = True + + if single_value: # optimization for a single value if (obj < -N or obj >= N): raise IndexError( @@ -5110,11 +5122,6 @@ def delete(arr, obj, axis=None): slobj2[axis] = slice(obj+1, None) new[tuple(slobj)] = arr[tuple(slobj2)] else: - _obj = obj - obj = np.asarray(obj) - if obj.size == 0 and not isinstance(_obj, np.ndarray): - obj = obj.astype(intp) - if obj.dtype == bool: if obj.shape != (N,): raise ValueError('boolean array argument obj to delete ' |