@@ -2611,15 +2611,20 @@ end
26112611
26122612function _vstack_plus (itr)
26132613 z = iterate (itr)
2614- isnothing (z) && throw (ArgumentError (" cannot stack an empty collection" ))
2614+ z === nothing && throw (ArgumentError (" cannot stack an empty collection" ))
26152615 val, state = z
26162616 val isa Union{AbstractArray, Tuple} || throw (ArgumentError (" cannot stack elements of type $(typeof (val)) " ))
26172617
26182618 axe = axes (val)
26192619 len = length (val)
26202620 n = haslength (itr) ? len* length (itr) : nothing
26212621
2622- v = similar (val isa Tuple ? (1 : 0 ) : val, eltype (val), something (n, len))
2622+ v = if val isa Tuple
2623+ T = mapreduce (typeof, promote_type, val)
2624+ similar (1 : 0 , T, something (n, len))
2625+ else
2626+ similar (val, something (n, len))
2627+ end
26232628 copyto! (v, 1 , val, firstindex (val), len)
26242629
26252630 w = _stack_rest! (v, 0 , n, axe, itr, state)
@@ -2630,12 +2635,16 @@ function _stack_rest!(v::AbstractVector, i, n, axe, itr, state)
26302635 len = prod (length, axe; init= 1 )
26312636 while true
26322637 z = iterate (itr, state)
2633- isnothing (z) && return v
2638+ z === nothing && return v
26342639 val, state = z
26352640 axes (val) == axe || throw (DimensionMismatch (
26362641 " expected a consistent size, got axes $(UnitRange .(axes (val))) compared to $(UnitRange .(axe)) for the first" ))
26372642 i += 1
2638- T′ = promote_type (eltype (v), eltype (val))
2643+ T′ = if val isa Tuple
2644+ promote_type (eltype (v), mapreduce (typeof, promote_type, val))
2645+ else
2646+ promote_type (eltype (v), eltype (val))
2647+ end
26392648 if T′ <: eltype (v)
26402649 if n isa Integer
26412650 copyto! (v, i* len+ 1 , val, firstindex (val), len)
0 commit comments