# Are arrays in Julia column major?

**URL:** <https://discourse.julialang.org/t/are-arrays-in-julia-column-major/95619>\
**Category:** New to Julia\
**Tags:** array\
**Created:** [March 6, 2023, 3:15pm UTC](https://discourse.julialang.org/t/are-arrays-in-julia-column-major/95619 "2023-03-06T15:15:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yanqing\_Jing](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yanqing_jing/32/47437_2.png) [@Yanqing\_Jing](https://discourse.julialang.org/u/Yanqing_Jing)\
**Post date:** [March 6, 2023, 3:15pm UTC](https://discourse.julialang.org/t/are-arrays-in-julia-column-major/95619/1 "2023-03-06T15:15:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [March 6, 2023, 3:17pm UTC](https://discourse.julialang.org/t/are-arrays-in-julia-column-major/95619/2 "2023-03-06T15:17:59Z")

</div>

1. Yes.
2. Regular `Array`s are continous, yes.
3. The algorithms themselves are usually orientation agnostic.

---

<div class="post-metadata">

**Author:** ![mikmoore](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikmoore/32/31109_2.png) [@mikmoore](https://discourse.julialang.org/u/mikmoore)\
**Post date:** [March 6, 2023, 4:36pm UTC](https://discourse.julialang.org/t/are-arrays-in-julia-column-major/95619/3 "2023-03-06T16:36:31Z")

</div>

> [@Sukera](#):
>
> The algorithms themselves are usually orientation agnostic.

However, do note that it is [usually fastest to traverse an `Array` column-by-column rather than row-by-row](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-column-major) (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.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [March 6, 2023, 8:14pm UTC](https://discourse.julialang.org/t/are-arrays-in-julia-column-major/95619/4 "2023-03-06T20:14:29Z")

</div>

> [@mikmoore](#):
>
> However, do note that it is [usually fastest to traverse an `Array` column-by-column rather than row-by-row](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-column-major) (and, generally, by earlier dimensions before later).

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.
