Skip to content

Commit 88be350

Browse files
committed
Fix offset1 for OffsetArrays
1 parent 8d5eeb6 commit 88be350

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/ArrayInterface.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,8 @@ function __init__()
11661166
@inline axes(A::OffsetArrays.OffsetArray) = Base.axes(A)
11671167
@inline _axes(A::OffsetArrays.OffsetArray, dim::Integer) = Base.axes(A, dim)
11681168
@inline axes(A::OffsetArrays.OffsetArray{T,N}, ::StaticInt{M}) where {T,M,N} = _axes(A, StaticInt{M}(), gt(StaticInt{M}(),StaticInt{N}()))
1169+
@inline known_offset1(::Type{<:OffsetArrays.OffsetArray}) = 1
1170+
@inline known_offset1(::Type{<:OffsetArrays.OffsetVector}) = nothing
11691171
end
11701172
end
11711173

src/stridelayout.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Returns the offset of the linear indices for `x`.
7878
@inline function offset1(x::X) where {X}
7979
o1 = known_offset1(X)
8080
if o1 === nothing
81-
return firstinde(x)
81+
return firstindex(x)
8282
else
8383
return static(o1)
8484
end

test/runtests.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,11 @@ end
681681
@test @inferred(ArrayInterface.offsets(Op)) === (11, 4, 8)
682682

683683
@test @inferred(ArrayInterface.offsets((1,2,3))) === (StaticInt(1),)
684-
684+
@test @inferred(ArrayInterface.offset1(O)) === StaticInt(1)
685+
@test @inferred(ArrayInterface.offset1(Op)) === StaticInt(1)
686+
o = OffsetArray(vec(A), 8);
687+
@test @inferred(ArrayInterface.offset1(o)) === 9
688+
685689
if VERSION v"1.6.0-DEV.1581"
686690
colors = [(R = rand(), G = rand(), B = rand()) for i 1:100];
687691

0 commit comments

Comments
 (0)