summaryrefslogtreecommitdiff
path: root/numpy/lib/arraysetops.py
diff options
context:
space:
mode:
authorMilesCranmer <miles.cranmer@gmail.com>2018-10-02 17:37:46 -0400
committerMilesCranmer <miles.cranmer@gmail.com>2022-06-09 20:35:01 -0400
commitd2ea8190c769c1c546f6f3fed495772aeeb90f0b (patch)
tree0eb50f7272d277169bd2f800d6cb003720e3a8b4 /numpy/lib/arraysetops.py
parentcedba623b110caf83f46edfa38cb4fbc0191e285 (diff)
downloadnumpy-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.py6
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))