Skip to content

Commit

Permalink
Fixups for #47383 (fixes runbenchmarks("sort")) (#47822)
Browse files Browse the repository at this point in the history
* add test demonstrating overflow in countsort

* fix overflow in countsort

* remove unnecessary type annotations (fixes tests)

This fixes the test failure because it allows for automatic conversion.
The manual for implementing the AbstractArray interface also does not recomend
a type signature for the value arg in setindex!.

Co-authored-by: Lilith Hafner <Lilith.Hafner@gmail.com>
  • Loading branch information
LilithHafner and Lilith Hafner authored Dec 13, 2022
1 parent 3d79993 commit 965bc7d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions base/sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -509,12 +509,12 @@ struct WithoutMissingVector{T, U} <: AbstractVector{T}
new{nonmissingtype(eltype(data)), typeof(data)}(data)
end
end
Base.@propagate_inbounds function Base.getindex(v::WithoutMissingVector, i::Integer)
Base.@propagate_inbounds function Base.getindex(v::WithoutMissingVector, i)
out = v.data[i]
@assert !(out isa Missing)
out::eltype(v)
end
Base.@propagate_inbounds function Base.setindex!(v::WithoutMissingVector{T}, x::T, i) where T
Base.@propagate_inbounds function Base.setindex!(v::WithoutMissingVector, x, i)
v.data[i] = x
v
end
Expand Down Expand Up @@ -830,7 +830,7 @@ maybe_reverse(o::ForwardOrdering, x) = x
maybe_reverse(o::ReverseOrdering, x) = reverse(x)
function _sort!(v::AbstractVector{<:Integer}, ::CountingSort, o::DirectOrdering, kw)
@getkw lo hi mn mx scratch
range = o === Reverse ? mn-mx : mx-mn
range = maybe_unsigned(o === Reverse ? mn-mx : mx-mn)
offs = 1 - (o === Reverse ? mx : mn)

counts = fill(0, range+1) # TODO use scratch (but be aware of type stability)
Expand All @@ -843,7 +843,7 @@ function _sort!(v::AbstractVector{<:Integer}, ::CountingSort, o::DirectOrdering,
lastidx = idx + counts[i] - 1
val = i-offs
for j = idx:lastidx
v[j] = val
v[j] = val isa Unsigned && eltype(v) <: Signed ? signed(val) : val
end
idx = lastidx + 1
end
Expand Down
2 changes: 2 additions & 0 deletions test/sorting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ end

@testset "Unions with missing" begin
@test issorted(sort(shuffle!(vcat(fill(missing, 10), rand(Int, 100)))))
@test issorted(sort(vcat(rand(Int8, 600), [missing])))
end

@testset "Specific algorithms" begin
Expand Down Expand Up @@ -897,6 +898,7 @@ end
@testset "Count sort near the edge of its range" begin
@test issorted(sort(rand(typemin(Int):typemin(Int)+100, 1000)))
@test issorted(sort(rand(typemax(Int)-100:typemax(Int), 1000)))
@test issorted(sort(rand(Int8, 600)))
end

# This testset is at the end of the file because it is slow.
Expand Down

5 comments on commit 965bc7d

@vtjnash
Copy link
Member

Choose a reason for hiding this comment

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

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here.

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(isdaily = true)

@vtjnash
Copy link
Member

Choose a reason for hiding this comment

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

laplace_sparse_matvec seemed to do quite well, but sorting performance apparently did really really poorly over the last 1 week and 50 commits 2a0eb70...965bc7d

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Your package evaluation job has completed - possible new issues were detected. A full report can be found here.

Please sign in to comment.