From b0e66ad754c2a2efeb8c6f39418e5bb7d3e388c5 Mon Sep 17 00:00:00 2001 From: MattHarrigan Date: Wed, 26 Oct 2016 11:01:05 -0400 Subject: ENH: fast track default kwargs for ediff1d Special case to_begin and to_end both equal to None, avoiding subsequent steps. Particulary faster for small arrays where overhead plays a big role. --- numpy/lib/arraysetops.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'numpy/lib/arraysetops.py') diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py index e63e09546..889415efe 100644 --- a/numpy/lib/arraysetops.py +++ b/numpy/lib/arraysetops.py @@ -81,6 +81,10 @@ def ediff1d(ary, to_end=None, to_begin=None): # force a 1d array ary = np.asanyarray(ary).ravel() + # fast track default case + if to_begin is None and to_end is None: + return ary[1:] - ary[:-1] + # get the length of the diff'd values l = len(ary) - 1 if l < 0: -- cgit v1.2.1