@@ -758,21 +758,25 @@ else
758
758
end
759
759
end
760
760
761
- _array_for (:: Type{T} , itr, :: HasLength ) where {T} = Vector {T} (undef, Int (length (itr):: Integer ))
762
- _array_for (:: Type{T} , itr, :: HasShape{N} ) where {T,N} = similar (Array{T,N}, axes (itr))
761
+ _array_for (:: Type{T} , itr, isz:: HasLength ) where {T} = _array_for (T, itr, isz, length (itr))
762
+ _array_for (:: Type{T} , itr, isz:: HasShape{N} ) where {T,N} = _array_for (T, itr, isz, axes (itr))
763
+ _array_for (:: Type{T} , itr, :: HasLength , len) where {T} = Vector {T} (undef, len)
764
+ _array_for (:: Type{T} , itr, :: HasShape{N} , axs) where {T,N} = similar (Array{T,N}, axs)
763
765
764
766
function collect (itr:: Generator )
765
767
isz = IteratorSize (itr. iter)
766
768
et = @default_eltype (itr)
767
769
if isa (isz, SizeUnknown)
768
770
return grow_to! (Vector {et} (), itr)
769
771
else
772
+ shape = isz isa HasLength ? length (itr) : axes (itr)
770
773
y = iterate (itr)
771
774
if y === nothing
772
775
return _array_for (et, itr. iter, isz)
773
776
end
774
777
v1, st = y
775
- collect_to_with_first! (_array_for (typeof (v1), itr. iter, isz), v1, itr, st)
778
+ arr = _array_for (typeof (v1), itr. iter, isz, shape)
779
+ return collect_to_with_first! (arr, v1, itr, st)
776
780
end
777
781
end
778
782
0 commit comments