Skip to content

Add a promotion mechanism to choose array concatenation return type #18472

Closed

Description

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    types and dispatchTypes, subtyping and method dispatch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions