diff --git a/Project.toml b/Project.toml index 1b9cd00..5a4ff39 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/functions.jl b/src/functions.jl index a4b10f5..ccd29b2 100644 --- a/src/functions.jl +++ b/src/functions.jl @@ -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 diff --git a/test/_functions.jl b/test/_functions.jl index 189bf1e..534af0f 100644 --- a/test/_functions.jl +++ b/test/_functions.jl @@ -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 @@ -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'