Skip to content

Commit b63cc5e

Browse files
committed
Depend on ArrayInterface
1 parent 05cae5c commit b63cc5e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@ version = "1.10.7"
44

55
[deps]
66
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
7+
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
8+
Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
79

810
[compat]
911
Adapt = "2, 3"
1012
Aqua = "0.5"
13+
ArrayInterface = "3"
1114
CatIndices = "0.2"
1215
DistributedArrays = "0.6"
1316
Documenter = "0.27"
1417
EllipsisNotation = "1"
1518
FillArrays = "0.11"
19+
Static = "0.3"
1620
StaticArrays = "1"
1721
julia = "0.7, 1"
1822

src/OffsetArrays.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
module OffsetArrays
22

3+
using ArrayInterface
34
using Base: tail, @propagate_inbounds
45
@static if !isdefined(Base, :IdentityUnitRange)
56
const IdentityUnitRange = Base.Slice
67
else
78
using Base: IdentityUnitRange
89
end
10+
using Static
911

1012
export OffsetArray, OffsetMatrix, OffsetVector
1113

@@ -119,6 +121,19 @@ struct OffsetArray{T,N,AA<:AbstractArray{T,N}} <: AbstractArray{T,N}
119121
end
120122
end
121123

124+
ArrayInterface.parent_type(::Type{O}) where {T,N,A<:AbstractArray{T,N},O<:OffsetArrays.OffsetArray{T,N,A}} = A
125+
function _offset_axis_type(::Type{T}, dim::StaticInt{D}) where {T,D}
126+
OffsetArrays.IdOffsetRange{Int,ArrayInterface.axes_types(T, dim)}
127+
end
128+
function ArrayInterface.axes_types(::Type{T}) where {T<:OffsetArrays.OffsetArray}
129+
ArrayInterface.Static.eachop_tuple(_offset_axis_type, Static.nstatic(Val(ndims(T))), ArrayInterface.parent_type(T))
130+
end
131+
@inline ArrayInterface.axes(A::OffsetArrays.OffsetArray) = Base.axes(A)
132+
@inline _axes(A::OffsetArrays.OffsetArray, dim::Integer) = Base.axes(A, dim)
133+
@inline function ArrayInterface.axes(A::OffsetArrays.OffsetArray{T,N}, ::StaticInt{M}) where {T,M,N}
134+
_axes(A, StaticInt{M}(), gt(StaticInt{M}(),StaticInt{N}()))
135+
end
136+
122137
"""
123138
OffsetVector(v, index)
124139

0 commit comments

Comments
 (0)