Description
openedon Sep 13, 2016
Currently, AbstractArray
concatenation methods like vcat
and hcat
call similar
on the first argument to choose the type of the array to return. This is quite arbitrary, and forces custom types to define methods which first convert their arguments before passing them to the AbstractArray
methods. This isn't efficient as it creates unnecessary copies. Examples include sparse matrices (#17685) and PooledDataArrays/CategoricalArrays (JuliaStats/DataArrays.jl#213), where the integer size of the underlying storage depends on the one used by the inputs.
I suggest we use the promotion mechanism to choose the return type instead. Custom array types would just have to define a function to indicate which type should "win". We could still keep the fallback on the first argument to ease the transition. The question is, can we use promote
for that, or do we need a different approach?