Documentation of eachindex

I find the documentation of eachindex a bit confusing when is says that:

If the arrays have different sizes and/or dimensionalities,
eachindex will return an iterable that spans the largest range along each dimension.

But my undestanding of the implementation of eachindex in abstractarray.jl and multidimensional.jl is that all array arguments must have the same length (for linear indexing) or the same axes (for Cartesian indexing) otherwise eachindex throws a DimensionMismatch exception.

To me, this means that it is always safe to use @inbounds for a loop like:

for i in eachindex(A, B, C, D)
   A[i] = B[i]*C[i] + D[i]
end

when A, B etc. are all (abstract) arrays.

4 Likes

i found this on the release notes of Julia 1.0:

eachindex(A, B...) now requires that all inputs have the same number of elements. When the chosen indexing is Cartesian, they must have the same axes.

so that documentation is outdated, i suppose

1 Like