diff options
author | MilesCranmer <miles.cranmer@gmail.com> | 2022-06-17 14:28:32 -0400 |
---|---|---|
committer | MilesCranmer <miles.cranmer@gmail.com> | 2022-06-17 14:28:32 -0400 |
commit | 3533b861650cff2de7680f1848cd05826f94d480 (patch) | |
tree | 9879dc67f1e39acf63a6afd1fb2d29b5d7ead06a /numpy/lib/arraysetops.py | |
parent | 31f739523f97afcec9baa6a872f25e06bd1a4104 (diff) | |
download | numpy-3533b861650cff2de7680f1848cd05826f94d480.tar.gz |
MAINT: Clean up integer overflow check in in1d
Diffstat (limited to 'numpy/lib/arraysetops.py')
-rw-r--r-- | numpy/lib/arraysetops.py | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py index a1eca1c01..339f4e60c 100644 --- a/numpy/lib/arraysetops.py +++ b/numpy/lib/arraysetops.py @@ -633,26 +633,20 @@ def in1d(ar1, ar2, assume_unique=False, invert=False, kind=None): if integer_arrays and kind in {None, 'dictionary'}: ar2_min = np.min(ar2) ar2_max = np.max(ar2) - ar1_size = ar1.size - ar2_size = ar2.size - # Check for integer overflow - with np.errstate(over='raise'): - try: - ar2_range = ar2_max - ar2_min + ar2_range = int(ar2_max) - int(ar2_min) - range_safe_from_overflow = True - except FloatingPointError: - range_safe_from_overflow = False + # Constraints on whether we can actually use the dictionary method: + range_safe_from_overflow = ar2_range < np.iinfo(ar2.dtype).max + below_memory_constraint = ar2_range <= 6 * (ar1.size + ar2.size) # Optimal performance is for approximately # log10(size) > (log10(range) - 2.27) / 0.927. - # However, here we set the requirement that + # However, here we set the requirement that by default # the intermediate array can only be 6x # the combined memory allocation of the original # arrays. See discussion on # https://github.com/numpy/numpy/pull/12065. - below_memory_constraint = ar2_range <= 6 * (ar1_size + ar2_size) if ( range_safe_from_overflow and |