@@ -758,21 +758,25 @@ else
758758 end
759759end
760760
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)
763765
764766function collect (itr:: Generator )
765767 isz = IteratorSize (itr. iter)
766768 et = @default_eltype (itr)
767769 if isa (isz, SizeUnknown)
768770 return grow_to! (Vector {et} (), itr)
769771 else
772+ shape = isz isa HasLength ? length (itr) : axes (itr)
770773 y = iterate (itr)
771774 if y === nothing
772775 return _array_for (et, itr. iter, isz)
773776 end
774777 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)
776780 end
777781end
778782
0 commit comments