jonniedie / ComponentArrays.jl

Arrays with arbitrarily nested named components.
MIT License
287 stars 34 forks source link

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

Open nrontsis opened 1 year ago

nrontsis commented 1 year ago

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))
jonniedie commented 1 year ago

Oh yeah, if you wouldn't mind, I'd appreciate that PR!

nrontsis commented 1 year ago

https://github.com/jonniedie/ComponentArrays.jl/issues/113 is also related

nrontsis commented 1 year ago

See #169