Skip to content

Commit

Permalink
Depend on ArrayInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
Tokazama committed Oct 15, 2021
1 parent 05cae5c commit b63cc5e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ version = "1.10.7"

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

[compat]
Adapt = "2, 3"
Aqua = "0.5"
ArrayInterface = "3"
CatIndices = "0.2"
DistributedArrays = "0.6"
Documenter = "0.27"
EllipsisNotation = "1"
FillArrays = "0.11"
Static = "0.3"
StaticArrays = "1"
julia = "0.7, 1"

Expand Down
15 changes: 15 additions & 0 deletions src/OffsetArrays.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
module OffsetArrays

using ArrayInterface
using Base: tail, @propagate_inbounds
@static if !isdefined(Base, :IdentityUnitRange)
const IdentityUnitRange = Base.Slice
else
using Base: IdentityUnitRange
end
using Static

export OffsetArray, OffsetMatrix, OffsetVector

Expand Down Expand Up @@ -119,6 +121,19 @@ struct OffsetArray{T,N,AA<:AbstractArray{T,N}} <: AbstractArray{T,N}
end
end

ArrayInterface.parent_type(::Type{O}) where {T,N,A<:AbstractArray{T,N},O<:OffsetArrays.OffsetArray{T,N,A}} = A
function _offset_axis_type(::Type{T}, dim::StaticInt{D}) where {T,D}
OffsetArrays.IdOffsetRange{Int,ArrayInterface.axes_types(T, dim)}
end
function ArrayInterface.axes_types(::Type{T}) where {T<:OffsetArrays.OffsetArray}
ArrayInterface.Static.eachop_tuple(_offset_axis_type, Static.nstatic(Val(ndims(T))), ArrayInterface.parent_type(T))
end
@inline ArrayInterface.axes(A::OffsetArrays.OffsetArray) = Base.axes(A)
@inline _axes(A::OffsetArrays.OffsetArray, dim::Integer) = Base.axes(A, dim)
@inline function ArrayInterface.axes(A::OffsetArrays.OffsetArray{T,N}, ::StaticInt{M}) where {T,M,N}
_axes(A, StaticInt{M}(), gt(StaticInt{M}(),StaticInt{N}()))
end

"""
OffsetVector(v, index)
Expand Down

0 comments on commit b63cc5e

Please sign in to comment.