Skip to content

hcat: type unstable based on the number of arguments #168

Open
@nrontsis

Description

@nrontsis

Hi, thanks for the very useful package!

I noticed that when doing hcat, I get varying output type based on the number of arguments. That is hcat(v, v) (where v is a ComponentVector) gives a ComponentMatrix, while hcat(v, v, v) gives a Matrix.

I think adding a method like below could resolve this:

function Base.hcat(vectors::ComponentVector{T,A,Tuple{Ax}}...) where {T,A,Ax}
    return ComponentMatrix(hcat((getdata(v) for v in vectors)...), Ax(), FlatAxis())
end

happy to open a PR if you think that would work.

Minimal Example:

using ComponentArrays
c = ComponentVector(a=1)
display(hcat(c, c))
display(hcat(c, c, c))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions