Indexing in Julia follows† the following rule: if b = a[idx]
for some vector index idx
, then b[j] = a[idx[j]]
. Since -1:1
has axes of Base.OneTo(3)
, b
has the same indexes. This is How It Should Be.
But you can do the following:
julia> using OffsetArrays
julia> a=zeros(-1:1);
julia> b = a[Base.IdentityUnitRange(-1:1)];
julia> axes(b)
(Base.IdentityUnitRange(-1:1),)
julia> axes(a)
(Base.IdentityUnitRange(-1:1),)
†or should follow, any violations are a bug