Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/OffsetArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,17 @@ Base.eachindex(::IndexLinear, A::OffsetVector) = axes(A, 1)
@inline Base.axes(A::OffsetArray, d) = d <= ndims(A) ? IdOffsetRange(axes(parent(A), d), A.offsets[d]) : IdOffsetRange(axes(parent(A), d))
@inline Base.axes1(A::OffsetArray{T,0}) where {T} = IdOffsetRange(axes(parent(A), 1)) # we only need to specialize this one

# Issue 128
# See https://github.com/JuliaLang/julia/issues/37274 for the issue reported in Base
# The fix https://github.com/JuliaLang/julia/pull/39404 should be available on v1.6
# The following method is added on older Julia versions to ensure correct behavior for OffsetVectors
if VERSION < v"1.6"
@inline function Base.compute_linindex(A::OffsetVector, I::NTuple{N,Any}) where N
IP = Base.fill_to_length(axes(A), Base.OneTo(1), Val(N))
Base.compute_linindex(first(LinearIndices(A)), 1, IP, I)
end
end

Base.similar(A::OffsetArray, ::Type{T}, dims::Dims) where T =
similar(parent(A), T, dims)
function Base.similar(A::AbstractArray, ::Type{T}, inds::Tuple{OffsetAxisKnownLength,Vararg{OffsetAxisKnownLength}}) where T
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,11 @@ end
d = OffsetArray(c, 1:2)
@test same_value(d, c)
@test axes(d,1) == 1:2

# Issue 128
a = OffsetArray(1:3, 0:2);
b = @view a[0]
@test b[] == b[1] == 1
end

@testset "iteration" begin
Expand Down