Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hcat(A, B) is SArray, but [ A ;; B] is not #1275

Open
dev10110 opened this issue Sep 11, 2024 · 1 comment
Open

hcat(A, B) is SArray, but [ A ;; B] is not #1275

dev10110 opened this issue Sep 11, 2024 · 1 comment

Comments

@dev10110
Copy link

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?

@dev10110 dev10110 changed the title hcat(A, B) is SArray, but [ A ;; B is not hcat(A, B) is SArray, but [ A ;; B] is not Sep 11, 2024
@mcabbott
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants