Skip to content

Indexing is not idempotent using Base.IdentityUnitRange #155

Closed
@jishnub

Description

@jishnub

This does not satisfy a[ax][i] == a[ax[i]]

julia> a = OffsetVector(3:4, 2:3)
3:4 with indices 2:3

julia> ax = Base.IdentityUnitRange(2:3)
Base.IdentityUnitRange(2:3)

julia> a[ax]
3:4

julia> a[ax][2]
4

julia> a[ax[2]]
3

The issue seems to be that a[ax] results in an UnitRange instead of an OffsetVector, and has different axes from ax. Eg something like this would be worse:

julia> a = OffsetVector(3:4, 10:11)
3:4 with indices 10:11

julia> ax = Base.IdentityUnitRange(10:11)
Base.IdentityUnitRange(10:11)

julia> a[ax]
3:4

julia> a[ax[10]]
3

julia> a[ax][10]
ERROR: BoundsError: attempt to access 2-element UnitRange{Int64} at index [10]
Stacktrace:
 [1] throw_boundserror(::UnitRange{Int64}, ::Int64) at ./abstractarray.jl:541
 [2] getindex(::UnitRange{Int64}, ::Int64) at ./range.jl:646
 [3] top-level scope at REPL[26]:1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions