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.