Skip to content

Commit 20951d3

Browse files
committed
Fall back to non-recursive Base.partialsort! for quickselect! of very large arrays
1 parent bf90f9f commit 20951d3

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "VectorizedStatistics"
22
uuid = "3b853605-1c98-4422-8364-4bd93ee0529e"
33
authors = ["C. Brenhin Keller", "Chris Elrod"]
4-
version = "0.5.5"
4+
version = "0.5.6"
55

66
[deps]
77
LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"

src/quicksort.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ sortnans!(A::AbstractArray{<:Integer}, iₗ::Int=firstindex(A), iᵤ::Int=lastin
7373

7474
# Partially sort `A` around the `k`th sorted element and return that element
7575
function quickselect!(A::AbstractArray, iₗ::Int=firstindex(A), iᵤ::Int=lastindex(A), k=(iₗ+iᵤ)÷2)
76+
# Fall back to Base implementation for very large arrays
77+
if iᵤ-iₗ > 20000
78+
return Base.Sort.partialsort!(view(A, iₗ:iᵤ), k-(iₗ-1))
79+
end
80+
7681
# Pick a pivot for partitioning
7782
N = iᵤ - iₗ + 1
7883
A[iₗ], A[k] = A[k], A[iₗ]

0 commit comments

Comments
 (0)