Skip to content
Merged
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
7 changes: 6 additions & 1 deletion src/collect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ ArrayInitializer(unwrap = t->false) = ArrayInitializer(unwrap, default_array)
(s::ArrayInitializer)(S, d) = s.unwrap(S) ? buildfromschema(typ -> s(typ, d), S) : s.default_array(S, d)

_reshape(v, itr) = _reshape(v, itr, Base.IteratorSize(itr))
_reshape(v, itr, ::Base.HasShape) = reshape(v, axes(itr))
_reshape(v, itr, ::Base.HasShape) = reshapestructarray(v, axes(itr))
_reshape(v, itr, ::Union{Base.HasLength, Base.SizeUnknown}) = v

# temporary workaround before it gets easier to support reshape with offset axis
reshapestructarray(v::AbstractArray, d) = reshape(v, d)
reshapestructarray(v::StructArray{T}, d) where {T} =
StructArray{T}(map(x -> reshapestructarray(x, d), fieldarrays(v)))

"""
`collect_structarray(itr, fr=iterate(itr); initializer = default_initializer)`

Expand Down
12 changes: 0 additions & 12 deletions src/structarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,3 @@ Base.copy(s::StructArray{T,N,C}) where {T,N,C} = StructArray{T,N,C}(C(copy(x) fo
function Base.reshape(s::StructArray{T}, d::Dims) where {T}
StructArray{T}(map(x -> reshape(x, d), fieldarrays(s)))
end

@static if !isdefined(Base, :IdentityUnitRange)
const IdentityUnitRange = Base.Slice
else
using Base: IdentityUnitRange
end

for typ in [:Integer, :(Base.OneTo), :UnitRange, :IdentityUnitRange]
@eval function Base.reshape(s::StructArray{T}, d::Tuple{$typ, Vararg{$typ}}) where {T}
StructArray{T}(map(x -> reshape(x, d), fieldarrays(s)))
end
end
4 changes: 0 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,6 @@ end
rs = reshape(s, (2, 2))
@test rs.a == [1 3; 2 4]
@test rs.b == ["a" "c"; "b" "d"]

os = reshape(s, -1:2)
@test os.a == OffsetArray([1,2,3,4], -2)
@test os.b == OffsetArray(["a","b","c","d"], -2)
end

@testset "lazy" begin
Expand Down