Hey all,
My use-case with Julia is working with very large 3D/4D arrays of images. For example, a 3D array might have dimensions (time, x, y)
. Generally these images will be processed individually so the ideal memory layout would be row-major, such that the pixels (floats) for each image will be stored contiguously.
Since Julia's arrays are column-major I had the idea of reversing the dimensions, e.g. (y, x, time)
, to have the right memory layout, and then maybe making a custom Array type that would automatically handle this inversion. So if a user creates a RowMajorArray{Float32}(undef, 1, 2, 3)
it will actually create a Array{Float32}(undef, 3, 2, 1)
, and indexing it at A[1, :, :]
would turn into A[:, :, 1]
. Does that sound like a good idea? I'd be interested to know if anyone else has done something like this.
Relevant things I found while Googling:
PyReverseDims()
: https://github.com/JuliaPy/PyCall.jl#from-julia-to-pythonPermutedDimsArray
does this. PermutedDimsArray(rand(1,2,3), (3,2,1))
.
But why not work with column major arrays?
E.g., why not work with y
x x
x time
, or permute to x
x y
x time
?
Oh neat, didn't know about PermutedDimsArray
. I guess the main reason to avoid working with column-major arrays is to keep a similar interface to arrays from Numpy/C, which is what most people working with my code will be used to. But maybe I should try it anyway...
Last updated: Dec 28 2024 at 04:38 UTC