StaticArrays.jl
StaticArrays.jl copied to clipboard
`hcat(A, B)` is SArray, but `[ A ;; B]` is not
Hi,
consider this MWE:
using LinearAlgebra, StaticArrays
A = @SMatrix randn(3, 4)
B = @SMatrix randn(3, 2)
as expected,
hcat(A, B) #returns 3×6 SMatrix{3, 6, Float64, 18}
but
[ A ;; B] # returns 3×6 Matrix{Float64}
If we compare this to vcat,
A = @SMatrix randn(3, 4)
B = @SMatrix randn(2, 4)
vcat(A, B) # returns 5×4 SMatrix{5, 4, Float64, 20} (as expected)
[ A ; B] # returns 5×4 SMatrix{5, 4, Float64, 20} (as expected)
So somehow, the array concatenation works for vcat but not for hcat.
Is this expected behavior?
array concatenation works for vcat but not for hcat
I think the problem is hvncat, while hcat and vcat are both fine:
julia> [A B] isa SMatrix
true
julia> Meta.@lower [A B]
:($(Expr(:thunk, CodeInfo(
1 ─ %1 = dynamic Base.hcat(Main.A, Main.B)
└── return %1
))))
julia> [A ;; B] isa Matrix
true
julia> Meta.@lower [A ;; B]
:($(Expr(:thunk, CodeInfo(
1 ─ %1 = dynamic Base.hvncat(2, Main.A, Main.B)
└── return %1
))))
julia> [A ;; B] == [A B] == hcat(A, B)
true
Nearly a duplicate of #1262, which is about hvcat.