Skip to content

Commit 5c88775

Browse files
authored
do not reshape during widening (#246)
* do not reshape during widening * bump project file
1 parent 1e77673 commit 5c88775

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "StructArrays"
22
uuid = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
3-
version = "0.6.12"
3+
version = "0.6.13"
44

55
[deps]
66
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

src/collect.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ _widenstructarray(dest::AbstractArray, i, ::Type{T}) where {T} = _widenarray(des
122122

123123
_widenarray(dest::AbstractArray{T}, i, ::Type{T}) where {T} = dest
124124
function _widenarray(dest::AbstractArray, i, ::Type{T}) where T
125-
new = similar(dest, T, length(dest))
125+
new = similar(dest, T)
126126
copyto!(new, firstindex(new), dest, firstindex(dest), i-1)
127-
new
127+
return new
128128
end
129129

130130
"""

test/runtests.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,11 +817,19 @@ pair_structarray((first, last)) = StructArray{Pair{eltype(first), eltype(last)}}
817817
end
818818

819819
@testset "collect2D" begin
820-
s = (l for l in [(a=i, b=j) for i in 1:3, j in 1:4])
820+
s = ((a=i, b=j) for i in 1:3, j in 1:4)
821821
v = collect_structarray(s)
822822
@test size(v) == (3, 4)
823+
@test eltype(v) == @NamedTuple{a::Int, b::Int}
823824
@test v.a == [i for i in 1:3, j in 1:4]
824825
@test v.b == [j for i in 1:3, j in 1:4]
826+
827+
s = (i == 1 ? (a=nothing, b=j) : (a=i, b=j) for i in 1:3, j in 1:4)
828+
v = collect_structarray(s)
829+
@test size(v) == (3, 4)
830+
@test eltype(v) == @NamedTuple{a::Union{Int, Nothing}, b::Int}
831+
@test v.a == [i == 1 ? nothing : i for i in 1:3, j in 1:4]
832+
@test v.b == [j for i in 1:3, j in 1:4]
825833
end
826834

827835
@testset "collectoffset" begin

0 commit comments

Comments
 (0)