Skip to content

Indexing is incorrect for views constructed with offset axes #39248

@jishnub

Description

@jishnub

This is the same issue as OffsetArrays#186, but I believe the fix should go into Base. We use the axis type IdOffsetRange defined in OffsetArrays to construct the view.

julia> using OffsetArrays

julia> using OffsetArrays: IdOffsetRange

julia> a = reshape(1:12, 3, 4)
3×4 reshape(::UnitRange{Int64}, 3, 4) with eltype Int64:
 1  4  7  10
 2  5  8  11
 3  6  9  12

julia> OffsetArrays.IdOffsetRange(3:4) == 3:4
true

julia> view(a, :, OffsetArrays.IdOffsetRange(3:4))
3×2 view(reshape(::UnitRange{Int64}, 3, 4), :, 3:4) with eltype Int64 with indices Base.OneTo(3)×OffsetArrays.IdOffsetRange(3:4):
 13  16
 14  17
 15  18

julia> view(a, :, OffsetArrays.IdOffsetRange(3:4)) ==  view(a, :, 3:4)
false

Clearly the view is constructed incorrectly when an IdOffsetRange is used.

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