Skip to content

Commit 85b1348

Browse files
committed
Fix integer overflow bug on lower bound when max range is set to maximum uint value
1 parent fb83375 commit 85b1348

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

newmap/unique_counts.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,23 @@ def binary_search(index_filename: Path,
289289
# Otherwise keep the current unique length
290290
unique_lengths[counted_positions])
291291

292+
# If we have a k-mer count of 1 and the current length queried is the
293+
# same as the lower bound (i.e. can't get smaller for a unique count)
294+
# This position has finished searching
295+
finished_search[counted_positions] = np.where(
296+
count_list == 1,
297+
current_length_query[counted_positions] == lower_length_bound[counted_positions],
298+
finished_search[counted_positions])
299+
300+
# If we have a k-mer count > 1 and the current length queried is the
301+
# same as the uppper bound (i.e. can't find a unique length or larger)
302+
# This position has finished searching
303+
finished_search[counted_positions] = np.where(
304+
count_list > 1,
305+
current_length_query[counted_positions] == upper_length_bound[counted_positions],
306+
finished_search[counted_positions])
307+
308+
292309
# Update the query length and bounds for the next iteration
293310

294311
# Lower the upper bounds of our search range on positions where
@@ -314,13 +331,6 @@ def binary_search(index_filename: Path,
314331
(upper_length_bound[counted_positions] / 2) +
315332
(lower_length_bound[counted_positions] / 2)).astype(data_type)
316333

317-
# If we have reduced our bounds to overlapping we have finished
318-
# searching on this position
319-
finished_search[counted_positions] = \
320-
finished_search[counted_positions] | \
321-
(upper_length_bound[counted_positions] <
322-
lower_length_bound[counted_positions])
323-
324334
iteration_count += 1
325335

326336
verbose_print(verbose,

0 commit comments

Comments
 (0)