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 and test sorting arrays with >1 dimension and custom similar #49392

Merged
merged 3 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1771,7 +1771,7 @@ function sort!(A::AbstractArray{T};
by=identity,
rev::Union{Bool,Nothing}=nothing,
order::Ordering=Forward, # TODO stop eagerly over-allocating.
scratch::Union{Vector{T}, Nothing}=similar(A, size(A, dims))) where T
scratch::Union{Vector{T}, Nothing}=Vector{T}(undef, size(A, dims))) where T
__sort!(A, Val(dims), maybe_apply_initial_optimizations(alg), ord(lt, by, rev, order), scratch)
end
function __sort!(A::AbstractArray{T}, ::Val{K},
Expand Down
14 changes: 14 additions & 0 deletions test/sorting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,20 @@ end
end
end

struct MyArray49392{T, N} <: AbstractArray{T, N}
data::Array{T, N}
end
Base.size(A::MyArray49392) = size(A.data)
Base.getindex(A::MyArray49392, i...) = getindex(A.data, i...)
Base.setindex!(A::MyArray49392, v, i...) = setindex!(A.data, v, i...)
Base.similar(A::MyArray49392, ::Type{T}, dims::Dims{N}) where {T, N} = MyArray49392(similar(A.data, T, dims))

@testset "Custom matrices (#49392)" begin
x = rand(10, 10)
y = MyArray49392(copy(x))
@test all(sort!(y, dims=2) .== sort!(x,dims=2))
end

# This testset is at the end of the file because it is slow.
@testset "searchsorted" begin
numTypes = [ Int8, Int16, Int32, Int64, Int128,
Expand Down