Skip to content

Commit

Permalink
propagate first and last for OffsetRanges
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Aug 22, 2021
1 parent f3fad96 commit 9b9b7f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/OffsetArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,9 @@ Broadcast.broadcast_unalias(dest::OffsetArray, src::OffsetArray) = parent(dest)
const OffsetRange{T} = OffsetVector{T,<:AbstractRange{T}}
const OffsetUnitRange{T} = OffsetVector{T,<:AbstractUnitRange{T}}

Base.step(a::OffsetRange) = step(parent(a))
for f in [:first, :last, :step]
@eval Base.$f(a::OffsetRange) = $f(parent(a))
end

Base.checkindex(::Type{Bool}, inds::AbstractUnitRange, or::OffsetRange) = Base.checkindex(Bool, inds, parent(or))

Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,14 @@ end
@test a == d
end
end

# Special methods for an OffsetRange
for r in Any[3:10, 3:1:10, UnitRange(3.0, 10.0), 3.0:1.0:10.0]
ro = OffsetArray(r)
@test first(ro) == first(r)
@test last(ro) == last(r)
@test step(ro) == step(r)
end
end

@testset "show/summary" begin
Expand Down

0 comments on commit 9b9b7f0

Please sign in to comment.