Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jishnub opened this issue Jul 17, 2020 · 1 comment · Fixed by #197
Closed

Comments

@jishnub
Copy link
Member

jishnub commented Jul 17, 2020

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.

@jishnub jishnub changed the title LinearIndexing zero-dimensional SubArray of OffsetVectors doesn't work as expected LinearIndexing for a zero-dimensional view of an OffsetVector doesn't work as expected Jul 17, 2020
@johnnychen94
Copy link
Member

Very nice catch! I think this is an edge case described in #100.

#101 fixes the issue described in #100 but doesn't cover this "edge" case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants