Skip to content

LinearIndexing for a zero-dimensional view of an OffsetVector doesn't work as expected #128

@jishnub

Description

@jishnub

For a zero-dimensional array a we usually expect a[] == a[1]. However this does not work with zero-D views of OffsetVectors

julia> a = OffsetArray(1:3, 0:2);

julia> b = @view a[0]
0-dimensional view(OffsetArray(::UnitRange{Int64}, 0:2), 0) with eltype Int64:
1

julia> b[]
1

julia> b[1]
2

This happens because for FastContiguousSubArrays, the indexing produces b[1] -> a[1]. Perhaps the offset calculation for the view needs to be different for OffsetVectors?

It appears adding the method

Base.compute_offset1(parent::OffsetVector, stride1::Integer, I::Tuple{Int}) = I[1] - stride1

fixes the issue in this particular case, however I'm not sure if this holds in general. I wonder if this is the correct resolution? In that case I can consider a PR.

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