Skip to content

Commit

Permalink
Fall back to non-recursive Base.partialsort! for quickselect! of …
Browse files Browse the repository at this point in the history
…very large arrays
  • Loading branch information
brenhinkeller committed Sep 12, 2023
1 parent bf90f9f commit 20951d3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "VectorizedStatistics"
uuid = "3b853605-1c98-4422-8364-4bd93ee0529e"
authors = ["C. Brenhin Keller", "Chris Elrod"]
version = "0.5.5"
version = "0.5.6"

[deps]
LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"
Expand Down
5 changes: 5 additions & 0 deletions src/quicksort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ sortnans!(A::AbstractArray{<:Integer}, iₗ::Int=firstindex(A), iᵤ::Int=lastin

# Partially sort `A` around the `k`th sorted element and return that element
function quickselect!(A::AbstractArray, iₗ::Int=firstindex(A), iᵤ::Int=lastindex(A), k=(iₗ+iᵤ)÷2)
# Fall back to Base implementation for very large arrays
if iᵤ-iₗ > 20000
return Base.Sort.partialsort!(view(A, iₗ:iᵤ), k-(iₗ-1))
end

# Pick a pivot for partitioning
N = iᵤ - iₗ + 1
A[iₗ], A[k] = A[k], A[iₗ]
Expand Down

2 comments on commit 20951d3

@brenhinkeller
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/91299

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.6 -m "<description of version>" 20951d33d23f54fa7e9026d8169b3dee40d1e301
git push origin v0.5.6

Please sign in to comment.