Are arrays in Julia column major?

Just learned that Julia arrays are column major, I have several questions regarding this.

  1. Is this true?
  2. Is the memory buffer for a julia array always continuous or is there a way to check?
  3. If arrays are column major, then what’s the preferred way to work with GPU or deep learning frameworks such as ONNX or TensorRT, doing transform whenever needed or is there some other ways?
  1. Yes.
  2. Regular Arrays are continous, yes.
  3. The algorithms themselves are usually orientation agnostic.
1 Like

However, do note that it is usually fastest to traverse an Array column-by-column rather than row-by-row (and, generally, by earlier dimensions before later).

Of course, if you wrap an Array in a lazy transpose (via A', LinearAlgebra.Transpose(A), PermutedDimsArray(A, (2,1)), or something similar), then it will become row-major and the reverse holds.

If the algorithm truly is orientation agnostic, at most you’ll have to flip the result (or change your interpretation of the result), as the algorithm will still work the same way, just interpreting our columns as rows internally.

If an algorithm isn’t, transposing it explicitly beforehand is usually rather trivial though.

1 Like