|
1 | 1 | module OffsetArrays |
2 | 2 |
|
| 3 | +using ArrayInterface |
3 | 4 | using Base: tail, @propagate_inbounds |
4 | 5 | @static if !isdefined(Base, :IdentityUnitRange) |
5 | 6 | const IdentityUnitRange = Base.Slice |
6 | 7 | else |
7 | 8 | using Base: IdentityUnitRange |
8 | 9 | end |
| 10 | +using Static |
9 | 11 |
|
10 | 12 | export OffsetArray, OffsetMatrix, OffsetVector |
11 | 13 |
|
@@ -119,6 +121,19 @@ struct OffsetArray{T,N,AA<:AbstractArray{T,N}} <: AbstractArray{T,N} |
119 | 121 | end |
120 | 122 | end |
121 | 123 |
|
| 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 | + |
122 | 137 | """ |
123 | 138 | OffsetVector(v, index) |
124 | 139 |
|
|
0 commit comments