# Eachindex efficiency on row-major arrays

**URL:** <https://discourse.julialang.org/t/eachindex-efficiency-on-row-major-arrays/50511>\
**Category:** General Usage\
**Created:** [November 20, 2020, 5:54pm UTC](https://discourse.julialang.org/t/eachindex-efficiency-on-row-major-arrays/50511 "2020-11-20T17:54:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rfourquet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rfourquet/32/3610_2.png) [@rfourquet](https://discourse.julialang.org/u/rfourquet)\
**Post date:** [November 20, 2020, 5:54pm UTC](https://discourse.julialang.org/t/eachindex-efficiency-on-row-major-arrays/50511/1 "2020-11-20T17:54:59Z")

</div>

I’m confused by these seemingly contradicting facts:

1. From `eachindex` docstring:

2. A transposed view of a `Matrix`, which has a row-major layout, has `eachindex` yielding indexes in a column-major way:

```julia
julia> A = collect(reshape(1:6, 2, 3))
2×3 Matrix{Int64}:
 1 3 5
 2 4 6

julia> AA = transpose(A)
3×2 LinearAlgebra.Transpose{Int64, Matrix{Int64}}:
 1 2
 3 4
 5 6

julia> for i in eachindex(AA)
           print(AA[i], " ")
       end
1 3 5 2 4 6

```

Is there a constraint that `eachindex` must follow column-major order? If so, where is it documented?

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [November 20, 2020, 6:13pm UTC](https://discourse.julialang.org/t/eachindex-efficiency-on-row-major-arrays/50511/2 "2020-11-20T18:13:33Z")

</div>

Seems that there should be an `eachindex` specific for `LinearAlgebra.Transpose` type, doesn’t it? Apparently there is no such specialization, all call the same function defined for `AbstractArrays`.

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [November 20, 2020, 10:42pm UTC](https://discourse.julialang.org/t/eachindex-efficiency-on-row-major-arrays/50511/3 "2020-11-20T22:42:14Z")

</div>

See [What depends on AbstractArray Iteration Order?](https://discourse.julialang.org/t/what-depends-on-abstractarray-iteration-order/49704)
