-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Faster searchsorted methods for range and array inputs #38527
Faster searchsorted methods for range and array inputs #38527
Conversation
8325e0e
to
a1e4c1f
Compare
Is it necessary to require one-based indexing at all? Perhaps |
Maybe! Would zero become I didn't feel confident enough to try to handle non one based indexed ranges. I assume that it would require adding test cases for stuff out in the ecosystem that I'm unaware of |
The only example I know if is the axes of OffsetArrays, which behave like this: julia> OffsetArray('a':'z', -10)
'a':1:'z' with indices -9:16
julia> axes(ans, 1)
OffsetArrays.IdOffsetRange(-9:16)
julia> axes(ans, 1)
OffsetArrays.IdOffsetRange(-9:16) The general idea here is similar to JuliaMath/IntervalSets.jl#63, in which it wasn't so hard to allow offsets. But that can depend on the package for tests. I think there is a (simplified?) implementation of this loaded for tests, e.g. https://github.com/JuliaLang/julia/blob/master/test/offsetarray.jl |
Is the addition of the new API (the bang versions of |
Not necessary, but logical I think. I think it would be odd to add the array-based methods without allowing preallocation. Do you think the PR needs to be split? |
Refs performance issue noted in #38527
a1e4c1f
to
ccc981c
Compare
Nice. Thanks! |
Refs performance issue noted in #38527
…Lang#40358) Refs performance issue noted in JuliaLang#38527
…Lang#40358) Refs performance issue noted in JuliaLang#38527
…Lang#40358) Refs performance issue noted in JuliaLang#38527
For searching through an AbstractRange, the fastest one can use
searchsortedfirst
to evaluate multiple values currently is:This PR provides the following, which only checks for one-based indexing and the length of
r
once, given they are expensive. It can also be preallocated:I didn't extend the methods for searching through AbstractVectors, as I didn't see a performance limitation with using those looped through values