Skip to content

Commit

Permalink
Do not specialize eachindex and size (#206)
Browse files Browse the repository at this point in the history
* do not specialize eachindex

* do not specialize size(::OffsetArray, d)

* Add tests
  • Loading branch information
jishnub authored Feb 19, 2021
1 parent c805039 commit ee0dced
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 0 additions & 4 deletions src/OffsetArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,7 @@ Base.parent(A::OffsetArray) = A.parent
# The goal would be to have `OffsetArray(CuArray) .+ 1 == OffsetArray{CuArray}`.
# Base.Broadcast.BroadcastStyle(::Type{<:OffsetArray{<:Any, <:Any, AA}}) where AA = Base.Broadcast.BroadcastStyle(AA)

Base.eachindex(::IndexCartesian, A::OffsetArray) = CartesianIndices(axes(A))
Base.eachindex(::IndexLinear, A::OffsetVector) = axes(A, 1)

@inline Base.size(A::OffsetArray) = size(parent(A))
@inline Base.size(A::OffsetArray, d) = size(parent(A), d)

@inline Base.axes(A::OffsetArray) = map(IdOffsetRange, axes(parent(A)), A.offsets)
@inline Base.axes(A::OffsetArray, d) = d <= ndims(A) ? IdOffsetRange(axes(parent(A), d), A.offsets[d]) : IdOffsetRange(axes(parent(A), d))
Expand Down
6 changes: 5 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,11 @@ end
@test_throws DimensionMismatch OffsetArray(A0, 0:2, 3:4)
@test_throws DimensionMismatch OffsetArray(A0, 0:1, 2:4)
@test eachindex(IndexLinear(), A) == eachindex(IndexLinear(), parent(A))
@test eachindex(IndexCartesian(), A) == CartesianIndices(A)
@test eachindex(IndexCartesian(), A) == CartesianIndices(A) == CartesianIndices(axes(A))
@test eachindex(S) == eachindex(IndexCartesian(), S) == CartesianIndices(S)
@test eachindex(IndexLinear(), S) == eachindex(IndexLinear(), A0)
A = ones(5:6)
@test eachindex(IndexLinear(), A) === axes(A, 1)
end

@testset "Scalar indexing" begin
Expand Down

0 comments on commit ee0dced

Please sign in to comment.