Syntax for constructing a 1x1 matrix

But functions can be defined for a reason (and compilers inline for a reason), so:

julia> mat(sc) = reshape([sc],1,1)
mat (generic function with 1 method)

julia> mat(5)
1×1 Array{Int64,2}:
 5

and better yet to consider:

julia> using StaticArrays

julia> smat(sc) = @SMatrix [sc]
smat (generic function with 1 method)

julia> smat(5)
1×1 StaticArrays.SArray{Tuple{1,1},Int64,2,1}:
 5

The little @code_llvm I looked at, made these methods preferable and ultimately more readable and correct.

1 Like