Eachindex efficiency on row-major arrays

I’m confused by these seemingly contradicting facts:

  1. From eachindex docstring:

    Create an iterable object for visiting each index of an AbstractArray A in an efficient manner

    (emphasize mine)

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

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?

1 Like

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.

4 Likes

See What depends on AbstractArray Iteration Order?

3 Likes