Skip to content

Commit

Permalink
do not reshape during widening (#246)
Browse files Browse the repository at this point in the history
* do not reshape during widening

* bump project file
  • Loading branch information
piever authored Sep 16, 2022
1 parent 1e77673 commit 5c88775
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "StructArrays"
uuid = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
version = "0.6.12"
version = "0.6.13"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
4 changes: 2 additions & 2 deletions src/collect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ _widenstructarray(dest::AbstractArray, i, ::Type{T}) where {T} = _widenarray(des

_widenarray(dest::AbstractArray{T}, i, ::Type{T}) where {T} = dest
function _widenarray(dest::AbstractArray, i, ::Type{T}) where T
new = similar(dest, T, length(dest))
new = similar(dest, T)
copyto!(new, firstindex(new), dest, firstindex(dest), i-1)
new
return new
end

"""
Expand Down
10 changes: 9 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -817,11 +817,19 @@ pair_structarray((first, last)) = StructArray{Pair{eltype(first), eltype(last)}}
end

@testset "collect2D" begin
s = (l for l in [(a=i, b=j) for i in 1:3, j in 1:4])
s = ((a=i, b=j) for i in 1:3, j in 1:4)
v = collect_structarray(s)
@test size(v) == (3, 4)
@test eltype(v) == @NamedTuple{a::Int, b::Int}
@test v.a == [i for i in 1:3, j in 1:4]
@test v.b == [j for i in 1:3, j in 1:4]

s = (i == 1 ? (a=nothing, b=j) : (a=i, b=j) for i in 1:3, j in 1:4)
v = collect_structarray(s)
@test size(v) == (3, 4)
@test eltype(v) == @NamedTuple{a::Union{Int, Nothing}, b::Int}
@test v.a == [i == 1 ? nothing : i for i in 1:3, j in 1:4]
@test v.b == [j for i in 1:3, j in 1:4]
end

@testset "collectoffset" begin
Expand Down

0 comments on commit 5c88775

Please sign in to comment.