diff options
author | MilesCranmer <miles.cranmer@gmail.com> | 2018-10-02 17:37:46 -0400 |
---|---|---|
committer | MilesCranmer <miles.cranmer@gmail.com> | 2022-06-09 20:35:01 -0400 |
commit | d2ea8190c769c1c546f6f3fed495772aeeb90f0b (patch) | |
tree | 0eb50f7272d277169bd2f800d6cb003720e3a8b4 /numpy/lib/arraysetops.py | |
parent | cedba623b110caf83f46edfa38cb4fbc0191e285 (diff) | |
download | numpy-d2ea8190c769c1c546f6f3fed495772aeeb90f0b.tar.gz |
MAINT: Optimize np.isin for boolean arrays
- This change converts boolean input to numpy.isin and numpy.in1d into uint8, allowing
the function to use the new optimized code
Diffstat (limited to 'numpy/lib/arraysetops.py')
-rw-r--r-- | numpy/lib/arraysetops.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py index c22c0ebf2..a0ee8d9b2 100644 --- a/numpy/lib/arraysetops.py +++ b/numpy/lib/arraysetops.py @@ -593,6 +593,12 @@ def in1d(ar1, ar2, assume_unique=False, invert=False): # Ensure that iteration through object arrays yields size-1 arrays if ar2.dtype == object: ar2 = ar2.reshape(-1, 1) + # Convert booleans to uint8 so we can use the fast integer algorithm + if ar1.dtype == np.bool_: + ar1 = ar1.view(np.uint8) + if ar2.dtype == np.bool_: + ar2 = ar2.view(np.uint8) + # Check if we can use a fast integer algorithm: integer_arrays = (np.issubdtype(ar1.dtype, np.integer) and np.issubdtype(ar2.dtype, np.integer)) |