From a1674ee2ffbc9e082f883729046976897124c8c4 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Fri, 15 Mar 2024 00:00:19 +0530 Subject: [PATCH 1/4] Resolve ambiguities in similar and reshape --- src/structarray.jl | 8 +++++--- test/runtests.jl | 8 +++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/structarray.jl b/src/structarray.jl index 0f13ad48..187850d9 100644 --- a/src/structarray.jl +++ b/src/structarray.jl @@ -290,13 +290,14 @@ for type in ( :(Tuple{Union{Integer, AbstractUnitRange}, Vararg{Union{Integer, AbstractUnitRange}}}), # disambiguation with Base :(Tuple{Union{Integer, Base.OneTo}, Vararg{Union{Integer, Base.OneTo}}}), + :(Tuple{Integer, Vararg{Integer}}), ) @eval function Base.similar(::Type{<:StructArray{T, N, C}}, sz::$(type)) where {T, N, C} return buildfromschema(typ -> similar(typ, sz), T, C) end - @eval function Base.similar(s::StructArray, S::Type, sz::$(type)) - return _similar(s, S, sz) + @eval function Base.similar(s::StructArray, ::Type{T}, sz::$(type)) where {T} + return _similar(s, T, sz) end end @@ -471,8 +472,9 @@ for type in ( # mimic OffsetArrays signature :(Tuple{Union{Integer, AbstractUnitRange, Colon}, Vararg{Union{Integer, AbstractUnitRange, Colon}}}), # disambiguation with Base + :(Tuple{Integer, Vararg{Integer}}), :(Tuple{Union{Integer, Base.OneTo}, Vararg{Union{Integer, Base.OneTo}}}), - :(Tuple{Vararg{Union{Colon, Integer}}}), + :(Tuple{Union{Colon, Integer}, Vararg{Union{Colon, Integer}}}), :(Tuple{Vararg{Union{Colon, Int}}}), :(Tuple{Colon}), ) diff --git a/test/runtests.jl b/test/runtests.jl index 0a57817c..87731746 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -396,6 +396,10 @@ end @test s isa Matrix{Float32} @test size(s) == (2, 2) + s = similar(t, Float32, Int8(2), 2) + @test s isa Matrix{Float32} + @test size(s) == (2, 2) + s = similar(t, Float32, 0:1, 2) @test s isa OffsetMatrix{Float32, Matrix{Float32}} @test axes(s) == (0:1, 1:2) @@ -1043,6 +1047,8 @@ end @test rs.a == [1 3; 2 4] @test rs.b == ["a" "c"; "b" "d"] + @test reshape(s, (Int8(2), 2)) == reshape(s, (2, 2)) + rs = reshape(s, (:,)) @test rs.a == s.a @test rs.b == s.b @@ -1630,5 +1636,5 @@ end end @testset "project quality" begin - Aqua.test_all(StructArrays, ambiguities=(; broken=true)) + Aqua.test_all(StructArrays) end From 411f7e9df676faf2b071c17fe4952b06f02cf901 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Fri, 15 Mar 2024 00:09:19 +0530 Subject: [PATCH 2/4] Test for ambiguities only on recent Julia versions --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 87731746..466ee776 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1636,5 +1636,5 @@ end end @testset "project quality" begin - Aqua.test_all(StructArrays) + Aqua.test_all(StructArrays, ambiguities = VERSION >= v"1.10") end From 19085230461d46e153d76eaacf204e01bd3eacde Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Wed, 27 Nov 2024 13:08:22 +0530 Subject: [PATCH 3/4] Update `similar` test to match failing case --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 466ee776..d945bab3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -396,7 +396,7 @@ end @test s isa Matrix{Float32} @test size(s) == (2, 2) - s = similar(t, Float32, Int8(2), 2) + s = similar(t, Float32, (Int8(2), 2)) @test s isa Matrix{Float32} @test size(s) == (2, 2) From b3868d763c44114f3567d719565bfd3e52cd14e3 Mon Sep 17 00:00:00 2001 From: Alexander Plavin Date: Sun, 23 Feb 2025 16:08:32 -0500 Subject: [PATCH 4/4] always test for ambiguities --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index d945bab3..64deb02f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1636,5 +1636,5 @@ end end @testset "project quality" begin - Aqua.test_all(StructArrays, ambiguities = VERSION >= v"1.10") + Aqua.test_all(StructArrays) end