Skip to content

Commit fc2fda4

Browse files
committed
to_dims methods
1 parent b63cc5e commit fc2fda4

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/OffsetArrays.jl

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,6 @@ struct OffsetArray{T,N,AA<:AbstractArray{T,N}} <: AbstractArray{T,N}
122122
end
123123

124124
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
136125

137126
"""
138127
OffsetVector(v, index)
@@ -299,10 +288,20 @@ Base.parent(A::OffsetArray) = A.parent
299288
# Base.Broadcast.BroadcastStyle(::Type{<:OffsetArray{<:Any, <:Any, AA}}) where AA = Base.Broadcast.BroadcastStyle(AA)
300289

301290
@inline Base.size(A::OffsetArray) = size(parent(A))
291+
@inline Base.size(A::OffsetArray, dim) = size(parent(A), ArrayInterface.to_dims(A, dim))
302292

303-
@inline Base.axes(A::OffsetArray) = map(IdOffsetRange, axes(parent(A)), A.offsets)
304-
@inline Base.axes(A::OffsetArray, d) = d <= ndims(A) ? IdOffsetRange(axes(parent(A), d), A.offsets[d]) : IdOffsetRange(axes(parent(A), d))
293+
@inline Base.axes(A::OffsetArray) = map(IdOffsetRange, ArrayInterface.axes(parent(A)), A.offsets)
294+
Base.axes(A::OffsetArray, d) = axes(A, ArrayInterface.to_dims(A, d))
295+
@inline function Base.axes(A::OffsetArray, d::Union{Int,StaticInt})
296+
d <= ndims(A) ? IdOffsetRange(axes(parent(A), d), A.offsets[d]) : IdOffsetRange(axes(parent(A), d))
297+
end
305298
@inline Base.axes1(A::OffsetArray{T,0}) where {T} = IdOffsetRange(axes(parent(A), 1)) # we only need to specialize this one
299+
function _offset_axis_type(::Type{T}, dim::StaticInt{D}) where {T,D}
300+
OffsetArrays.IdOffsetRange{Int,ArrayInterface.axes_types(T, dim)}
301+
end
302+
function ArrayInterface.axes_types(::Type{T}) where {T<:OffsetArrays.OffsetArray}
303+
Static.eachop_tuple(_offset_axis_type, Static.nstatic(Val(ndims(T))), ArrayInterface.parent_type(T))
304+
end
306305

307306
# Issue 128
308307
# See https://github.com/JuliaLang/julia/issues/37274 for the issue reported in Base

src/axes.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ end
164164
offset_coerce(::Type{I}, r::AbstractUnitRange) where I<:AbstractUnitRange =
165165
convert(I, r)::I, 0
166166

167+
ArrayInterface.parent_type(::Type{<:IdOffsetRange{<:Any,I}}) where {I} = I
167168
@inline Base.parent(r::IdOffsetRange) = r.parent
168169
@inline Base.axes(r::IdOffsetRange) = (Base.axes1(r),)
169170
@inline Base.axes1(r::IdOffsetRange) = IdOffsetRange(Base.axes1(r.parent), r.offset)

0 commit comments

Comments
 (0)