@@ -666,21 +666,25 @@ else
666
666
end
667
667
end
668
668
669
- _array_for (:: Type{T} , itr, :: HasLength ) where {T} = Vector {T} (undef, Int (length (itr):: Integer ))
670
- _array_for (:: Type{T} , itr, :: HasShape{N} ) where {T,N} = similar (Array{T,N}, axes (itr))
669
+ _array_for (:: Type{T} , itr, isz:: HasLength ) where {T} = _array_for (T, itr, isz, length (itr))
670
+ _array_for (:: Type{T} , itr, isz:: HasShape{N} ) where {T,N} = _array_for (T, itr, isz, axes (itr))
671
+ _array_for (:: Type{T} , itr, :: HasLength , len) where {T} = Vector {T} (undef, len)
672
+ _array_for (:: Type{T} , itr, :: HasShape{N} , axs) where {T,N} = similar (Array{T,N}, axs)
671
673
672
674
function collect (itr:: Generator )
673
675
isz = IteratorSize (itr. iter)
674
676
et = @default_eltype (itr)
675
677
if isa (isz, SizeUnknown)
676
678
return grow_to! (Vector {et} (), itr)
677
679
else
680
+ shape = isz isa HasLength ? length (itr) : axes (itr)
678
681
y = iterate (itr)
679
682
if y === nothing
680
683
return _array_for (et, itr. iter, isz)
681
684
end
682
685
v1, st = y
683
- collect_to_with_first! (_array_for (typeof (v1), itr. iter, isz), v1, itr, st)
686
+ arr = _array_for (typeof (v1), itr. iter, isz, shape)
687
+ return collect_to_with_first! (arr, v1, itr, st)
684
688
end
685
689
end
686
690
0 commit comments