Is there an array literal that gives me this object (and a variation with some integer elements in some of the vectors)?
julia> ...
3×5 Matrix{Vector{Int64}}:
[] [] [] [] []
[] [] [] [] []
[] [] [] [] []
My use case is writing unit tests where I expect a specific matrix of vectors as output, which I wanted to write literally. Of course I can construct the matrix step by step, but for small matrices, writing the literals makes the tests more readable in my opinion.
What I tried so far:
When I have a matrix of vectors, e.g.
julia> m = [Int[] for _ in 1:3, _ in 1:5]
3×5 Matrix{Vector{Int64}}:
[] [] [] [] []
[] [] [] [] []
[] [] [] [] []
I can @show
it, giving
julia> @show m
m = [Int64[] Int64[] Int64[] Int64[] Int64[]; Int64[] Int64[] Int64[] Int64[] Int64[]; Int64[] Int64[] Int64[] Int64[] Int64[]]
However, pasting this literal back into the REPL, I get a different object:
julia> new_m = [Int64[] Int64[] Int64[] Int64[] Int64[]; Int64[] Int64[] Int64[] Int64[] Int64[]; Int64[] Int64[] Int64[] Int64[] Int64[]]
0×5 Matrix{Int64}
I think I get what’s going on – the individual arrays in the literal are directly concatenated together to form a “flat” array instead of an array of vectors, like here:
julia> [[1] [2] [3] [4]; [5] [6] [7] [8]]
2×4 Matrix{Int64}:
1 2 3 4
5 6 7 8
This (presumably?) is intended to make concatenating rows/columns into larger matrices more convenient, but I think it would be great if copy-pasting the expression from @show
would give the correct object, like for many other objects. I tried different variations of the above literal to parse to a matrix of vectors, but so far without success.
Any help or pointers would be greatly appreciated! I feel like I’ve read something about this somewhere, but I couldn’t find it right now…