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 inplace sort! on Julia 1.9 with non int eltypes #153

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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 Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AxisKeys"
uuid = "94b1ba4f-4ee9-5380-92f1-94cde586c3c5"
license = "MIT"
version = "0.2.14"
version = "0.2.15"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Expand Down
6 changes: 5 additions & 1 deletion src/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ function Base.sort(A::KeyedVector; kw...)
end

function Base.sort!(A::KeyedVector; kw...)
perm = sortperm(parent(A); kw...)
@static if VERSION >= v"1.9"
perm = sortperm(parent(A); kw..., scratch=Vector{Int}(undef, length(A)))
else
perm = sortperm(parent(A); kw...)
end
permute!(axiskeys(A,1), perm) # error if keys cannot be sorted, could treat like push!
permute!(parent(A), perm)
A
Expand Down
11 changes: 10 additions & 1 deletion test/_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ using NamedDims: unname
M = wrapdims(rand(Int8, 3,4), r='a':'c', c=2:5)
MN = NamedDimsArray(M.data.data, r='a':'c', c=2:5)
V = wrapdims(rand(1:99, 10), v=10:10:100)
# used for an inplace sort! later, so axiskeys need to be a container
# that supports setindex!
VF = wrapdims(rand(10), v=collect(10:10:100))

VN = NamedDimsArray(V.data.data, v=10:10:100)
A3 = wrapdims(rand(Int8, 3,4,2), r='a':'c', c=2:5, p=[10.0, 20.0])
# used for an inplace sort! later, so axiskeys need to be a container
# that supports setindex!
A3 = wrapdims(rand(Int8, 3,4,2), r=collect('a':'c'), c=collect(2:5), p=[10.0, 20.0])

@testset "dims" begin

Expand Down Expand Up @@ -87,6 +93,9 @@ end
@testset "sort & reverse" begin

@test sort(V)(20) == V(20)
# need to test with non integer eltypes:
@test sort!(deepcopy(VF))(20) == VF(20)
@test first(sort!(float.(A3); dims=1)) == first(sort(A3; dims=1))

@test axiskeys(sort(M, dims=:c), :c) isa Base.OneTo
@test axiskeys(sort(M, dims=:c), :r) == 'a':'c'
Expand Down
Loading