diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2018-01-31 00:56:36 -0800 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2018-01-31 01:01:41 -0800 |
commit | 2b417df83202df9ea67f1eec76985a3da20cb86c (patch) | |
tree | 13a0e2e15f50f2ee49aa45e2cbd45b7fbadcdcef /numpy/lib/arraysetops.py | |
parent | 3c05221dd443323e7948eadf8105c0b52e760f70 (diff) | |
download | numpy-2b417df83202df9ea67f1eec76985a3da20cb86c.tar.gz |
MAINT: Remove special-casing of empty arrays in unique_1d
Diffstat (limited to 'numpy/lib/arraysetops.py')
-rw-r--r-- | numpy/lib/arraysetops.py | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py index 78d4536c0..e1c1c8803 100644 --- a/numpy/lib/arraysetops.py +++ b/numpy/lib/arraysetops.py @@ -268,34 +268,26 @@ def _unique1d(ar, return_index=False, return_inverse=False, optional_indices = return_index or return_inverse - if ar.size == 0: - ret = (ar,) - if return_index: - ret += (np.empty(0, np.intp),) - if return_inverse: - ret += (np.empty(0, np.intp),) - if return_counts: - ret += (np.empty(0, np.intp),) - return ret - if optional_indices: perm = ar.argsort(kind='mergesort' if return_index else 'quicksort') aux = ar[perm] else: ar.sort() aux = ar - flag = np.concatenate(([True], aux[1:] != aux[:-1])) + mask = np.empty(aux.shape, dtype=np.bool_) + mask[:1] = True + mask[1:] = aux[1:] != aux[:-1] - ret = (aux[flag],) + ret = (aux[mask],) if return_index: - ret += (perm[flag],) + ret += (perm[mask],) if return_inverse: - iflag = np.cumsum(flag) - 1 + imask = np.cumsum(mask) - 1 inv_idx = np.empty(ar.shape, dtype=np.intp) - inv_idx[perm] = iflag + inv_idx[perm] = imask ret += (inv_idx,) if return_counts: - idx = np.concatenate(np.nonzero(flag) + ([ar.size],)) + idx = np.concatenate(np.nonzero(mask) + ([ar.size],)) ret += (np.diff(idx),) return ret |