From 6f63cae90de5e439f8ba75b13f2b21aec854795b Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Wed, 6 Mar 2024 10:32:36 -0600 Subject: [PATCH 1/3] add tests for sorting with non int eltypes --- test/_functions.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/_functions.jl b/test/_functions.jl index 189bf1e..d4ad2ee 100644 --- a/test/_functions.jl +++ b/test/_functions.jl @@ -4,6 +4,7 @@ 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) + 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]) @@ -87,6 +88,9 @@ end @testset "sort & reverse" begin @test sort(V)(20) == V(20) + # need to test with non integer eltypes: + @test sort!(float.(V))(20) == V(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' From de4b4361f7596d672a0546aad441284309acbd1a Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Wed, 6 Mar 2024 10:48:44 -0600 Subject: [PATCH 2/3] stopgap fix for sort! problems on 1.9+ --- src/functions.jl | 6 +++++- test/_functions.jl | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) 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 d4ad2ee..534af0f 100644 --- a/test/_functions.jl +++ b/test/_functions.jl @@ -4,9 +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 @@ -89,7 +94,7 @@ end @test sort(V)(20) == V(20) # need to test with non integer eltypes: - @test sort!(float.(V))(20) == V(20) + @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 From e3ba059c8475808bec19b1dc30170335e9e0470a Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Wed, 6 Mar 2024 10:52:01 -0600 Subject: [PATCH 3/3] patch bump --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"