Update: I added some asserts.
module A
using BenchmarkTools
const a = rand(3,3)
const b = rand(3,3)
const c = rand(3,3)
const d = rand(3,3)
const e = rand(3,3)
@btime [a,b,c,d,e]
# fails
# @assert size([a,b,c,d,e]) == (1,5)
# fails
# @assert [a,b,c,d,e] isa Matrix{Matrix{Float64}}
@btime [a,b,c,d,e][:,:]
# fails
# @assert size([a,b,c,d,e][:,:]) == (1,5)
@assert [a,b,c,d,e][:,:] isa Matrix{Matrix{Float64}}
@btime transpose([a,b,c,d,e][:,:])
@assert size(transpose([a,b,c,d,e][:,:])) == (1,5)
# fails
# @assert transpose([a,b,c,d,e][:,:]) isa Matrix{Matrix{Float64}}
@btime permutedims([a,b,c,d,e][:,:])
@assert size(permutedims([a,b,c,d,e][:,:])) == (1,5)
@assert permutedims([a,b,c,d,e][:,:]) isa Matrix{Matrix{Float64}}
@btime permutedims([a,b,c,d,e])
@assert size(permutedims([a,b,c,d,e])) == (1,5)
@assert permutedims([a,b,c,d,e]) isa Matrix{Matrix{Float64}}
@btime getfield.(hcat(Ref(a),Ref(b),Ref(c),Ref(d),Ref(e)),:x)
@assert size(getfield.(hcat(Ref(a),Ref(b),Ref(c),Ref(d),Ref(e)),:x)) == (1,5)
@assert getfield.(hcat(Ref(a),Ref(b),Ref(c),Ref(d),Ref(e)),:x) isa Matrix{Matrix{Float64}}
function mcat(args::Matrix{T}...) where T
l = length(args)
r = Matrix{Matrix{T}}(undef,1,l)
for (i,arg) in enumerate(args)
@inbounds r[1,i] = arg
end
r
end
@btime mcat(a,b,c,d,e)
@assert size(mcat(a,b,c,d,e)) == (1,5)
@assert mcat(a,b,c,d,e) isa Matrix{Matrix{Float64}}
end
julia> include("test.jl")
54.884 ns (1 allocation: 128 bytes)
140.585 ns (2 allocations: 256 bytes)
141.619 ns (2 allocations: 256 bytes)
233.428 ns (3 allocations: 384 bytes)
134.188 ns (3 allocations: 224 bytes)
329.203 ns (7 allocations: 336 bytes)
63.907 ns (1 allocation: 128 bytes)
Main.A