JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.91k stars 5.49k forks source link

Allow `stack` on empty collection #55735

Open jariji opened 2 months ago

jariji commented 2 months ago
julia> stack(Vector{Int}[[], [], []]; dims=1)
3×0 Matrix{Int64}

julia> stack(Vector{Int}[[], []]; dims=1)
2×0 Matrix{Int64}

julia> stack(Vector{Int}[[]]; dims=1)
1×0 Matrix{Int64}

julia> stack(Vector{Int}[]; dims=1)
ERROR: LoadError: ArgumentError: `stack` on an empty collection is not allowed

Following the pattern it seems like that last one can be a 0x0 Matrix{Int64}. Supporting the empty case can be helpful for generic programming.

cc @mcabbott @LilithHafner for stack-related work.

mcabbott commented 2 months ago

This was removed from #43334 because it introduced type-instabilities. (Done here, scroll up or see discussion starting here.)

At the time I thought that some more methods of similar could make this work, but haven't made a PR.