Dealing with "C style" memory layout

In julia arrays are stored using the fortran memory ordering. When interacting with other languages that use “C” ordering it is often necessary to convert between the two.
Usually I do this in an add hoc manner like

permutedims(reshape(arr, reverse(size(arr))), (4,3,2,1))

but that is hard to read, error prone and maybe not optimally fast.

  • How do other people deal with this? I am mostly interested in ndims(arr) > 2.
  • Is there a dedicated package for doing such conversions?
  • Is there maybe a dedicated CArray <: AbstractArray somewhere that is backed by “C-ordering”?
  • Is there a more performant way than the above hack?

you can just do permutedims(arr, (4,3,2,1)), no?

1 Like

That does look plausible, I think it might be that I am just confused :sweat_smile: