Skip to content

Commit 22bb669

Browse files
authored
Merge pull request #168 from JuliaArrays/offset1offsetarrays
Fix offset1 for OffsetArrays
2 parents d668a41 + b2414e0 commit 22bb669

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

src/ArrayInterface.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,8 @@ function __init__()
935935
@inline axes(A::OffsetArrays.OffsetArray) = Base.axes(A)
936936
@inline _axes(A::OffsetArrays.OffsetArray, dim::Integer) = Base.axes(A, dim)
937937
@inline axes(A::OffsetArrays.OffsetArray{T,N}, ::StaticInt{M}) where {T,M,N} = _axes(A, StaticInt{M}(), gt(StaticInt{M}(),StaticInt{N}()))
938+
@inline known_offset1(::Type{<:OffsetArrays.OffsetArray}) = 1
939+
@inline known_offset1(::Type{<:OffsetArrays.OffsetVector}) = nothing
938940
end
939941
end
940942

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,10 @@ end
681681
@test @inferred(ArrayInterface.offsets(Op)) === (11, 4, 8)
682682

683683
@test @inferred(ArrayInterface.offsets((1,2,3))) === (StaticInt(1),)
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
684688

685689
@testset "StrideIndex" begin
686690
ap_index = ArrayInterface.StrideIndex(Ap)

0 commit comments

Comments
 (0)