Seems like the behavior of CartesianIndices
changed at some point.
Julia1.2:
julia> a = reshape(collect(1:12), 4, 3);
julia> v = view(a, 2, :);
julia> for (i_view, ci_orig) in zip(eachindex(v), CartesianIndices(parentindices(v)))
@show i_view, ci_orig
end
(i_view, ci_orig) = (1, CartesianIndex(2, 1))
(i_view, ci_orig) = (2, CartesianIndex(2, 2))
(i_view, ci_orig) = (3, CartesianIndex(2, 3))
Julia1.6:
julia> a = reshape(collect(1:12), 4, 3);
julia> v = view(a, 2, :);
julia> for (i_view, ci_orig) in zip(eachindex(v), CartesianIndices(parentindices(v)))
@show i_view, ci_orig
end
(i_view, ci_orig) = (1, CartesianIndex(1, 1))
(i_view, ci_orig) = (2, CartesianIndex(2, 1))
(i_view, ci_orig) = (3, CartesianIndex(1, 2))
The second method I gave still works, although ironically it was supposed to be the less stable one…