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

Resolve ambiguities in similar and reshape #307

Open
wants to merge 2 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
8 changes: 5 additions & 3 deletions src/structarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,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

Expand Down Expand Up @@ -470,8 +471,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}),
)
Expand Down
8 changes: 7 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,10 @@ end
@test s isa Matrix{Float32}
@test size(s) == (2, 2)

s = similar(t, Float32, Int8(2), 2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems to work without this PR as well

@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)
Expand Down Expand Up @@ -1000,6 +1004,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
Expand Down Expand Up @@ -1543,5 +1549,5 @@ end
end

@testset "project quality" begin
Aqua.test_all(StructArrays, ambiguities=(; broken=true))
Aqua.test_all(StructArrays, ambiguities = VERSION >= v"1.10")
end
Loading