Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overflow in searchsorted* #286

Merged
merged 6 commits into from May 20, 2022

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented May 20, 2022

Fixes #285, but this doesn't fix all issues (as certain tests are broken). However, I think searchsortedfirst and searchsortedlast should be fixed.

@codecov
Copy link

codecov bot commented May 20, 2022

Codecov Report

Merging #286 (b73570d) into master (d8c8d42) will decrease coverage by 0.36%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #286      +/-   ##
==========================================
- Coverage   95.90%   95.53%   -0.37%     
==========================================
  Files           5        5              
  Lines         464      426      -38     
==========================================
- Hits          445      407      -38     
  Misses         19       19              
Impacted Files Coverage Δ
src/OffsetArrays.jl 97.47% <100.00%> (-0.31%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d8c8d42...b73570d. Read the comment docs.

@johnnychen94
Copy link
Member

Hmmm, the failure on 1.0 is concerning. Do you know why that happens?

@jishnub
Copy link
Member Author

jishnub commented May 20, 2022

Yes, should be fixed now. I had made a mistake in the test, but since empty ranges are equal in 1.6+, the test had passed.

@jishnub
Copy link
Member Author

jishnub commented May 20, 2022

I feel like we're unnecessarily complicating matters here. We should simply pass the searchsorted to the parent, and add the offset. I've tried this locally and this resolves all issues.

@jishnub
Copy link
Member Author

jishnub commented May 20, 2022

I think the codecov changes are ok, looks good to merge

@jishnub jishnub changed the title Partly fix overflow in searchsorted* Fix overflow in searchsorted* May 20, 2022
@jishnub jishnub changed the title Fix overflow in searchsorted* Fix overflow in searchsorted* May 20, 2022
for f in [:searchsortedfirst, :searchsortedlast, :searchsorted]
_safe_f = Symbol("_safe_" * String(f))
@eval function $_safe_f(v::OffsetArray, x, ilo, ihi, o::Base.Ordering)
offset = firstindex(v) - firstindex(parent(v))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if v is an offset vector of another offset vector? E.g., OffsetVector of PaddedView?

Edit: oh never mind, it seems to work just fine by delegating to the parent method.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'll add some tests, good to be sure

@jishnub jishnub merged commit 44f9b50 into JuliaArrays:master May 20, 2022
@jishnub jishnub deleted the searchsortedoverflow branch May 20, 2022 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Overflow in searchsorted*
2 participants