Using Luxor.Table to visualize Julia 2D matrix results in transposed view

Hi, I’m stumbling across the fact that Luxor.Table looks row-major but Julia matrices are column-major.
How can I “swap” dimension indices between source matrix read access and Luxor.Table write access?

using Luxor

width = 100
height = 100

m = [[1,2] [3,4]]

table = Table(size(m)[2], size(m)[1], 20, 20, Point(width / 2, height / 2))

Drawing(width, height, :rec)
background("darkgray")
fontsize(22)
fontface("Monaco")
sethue("red")

for n in eachindex(table)
    Luxor.text(string(m[n]), table[n], halign=:center, valign=:middle)
end

snapshot(fname=string(@__DIR__, "/tmp/test.png"))

finish()

display(m)

Result:
test

display(m) output:

2×2 Matrix{Int64}:
 1  3
 2  4

My experiments with the CartesianIndices() iterator failed so far. I want to avoid permutedims(m) because this seems to be slow, but I may be wrong about this…

You could iterate the matrix:

@draw begin
    background("grey10")
    sethue("purple")
    fontsize(100)
    m = [[1, 2, 3] [4, 5, 6]]
    t = Table(size(m)..., 100, 100)
    for ci in CartesianIndices(m)
        row, col = Tuple(ci)
        text(string(m[row, col]),
            t[row, col],
            halign=:center,
            valign=:middle)
        circle(t[row, col], 50, :stroke)
    end
end

or iterate the table:

@draw begin
    background("grey10")
    sethue("purple")
    fontsize(100)
    m = [[1, 2, 3] [4, 5, 6]]
    t = Table(size(m)..., 100, 100)
    for cell in t
        row, col = t.currentrow, t.currentcol
        text(string(m[row, col]),
            t[row, col],
            halign=:center,
            valign=:middle)
        circle(t[row, col], 50, :stroke)
    end
end

with the same result:

There are examples of using CartesianIndices in the docs.

I want to avoid permutedims(m) because this seems to be slow, but I may be wrong about this…

Depends on the size of m I suppose. Perhaps you could benchmark it…