Skip to content

Commit 320989a

Browse files
authored
fix code instability of axes (#119)
* fix code instability of axes * construct axes using axes of parent array
1 parent bd7608e commit 320989a

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/OffsetArrays.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ Base.eachindex(::IndexLinear, A::OffsetVector) = axes(A, 1)
9292
@inline Base.size(A::OffsetArray, d) = size(parent(A), d)
9393

9494
@inline Base.axes(A::OffsetArray) = map(IdOffsetRange, axes(parent(A)), A.offsets)
95-
@inline Base.axes(A::OffsetArray, d) = d <= ndims(A) ? IdOffsetRange(axes(parent(A), d), A.offsets[d]) : Base.OneTo(1)
96-
@inline Base.axes1(A::OffsetArray{T,0}) where {T} = Base.OneTo(1) # we only need to specialize this one
95+
@inline Base.axes(A::OffsetArray, d) = d <= ndims(A) ? IdOffsetRange(axes(parent(A), d), A.offsets[d]) : IdOffsetRange(axes(parent(A), d))
96+
@inline Base.axes1(A::OffsetArray{T,0}) where {T} = IdOffsetRange(axes(parent(A), 1)) # we only need to specialize this one
9797

9898
const OffsetAxis = Union{Integer, UnitRange, Base.OneTo, IdentityUnitRange, IdOffsetRange, Colon}
9999
Base.similar(A::OffsetArray, ::Type{T}, dims::Dims) where T =

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ end
160160
A0 = [1 3; 2 4]
161161
A = OffsetArray(A0, (-1,2)) # IndexLinear
162162
S = OffsetArray(view(A0, 1:2, 1:2), (-1,2)) # IndexCartesian
163+
@test axes(A) === axes(S)
163164
@test axes(A) == axes(S) == (0:1, 3:4)
165+
@test axes(A, 1) === OffsetArrays.IdOffsetRange(Base.OneTo(2), -1)
164166
@test size(A) == size(A0)
165167
@test size(A, 1) == size(A0, 1)
166168
@test length(A) == length(A0)

0 commit comments

Comments
 (0)