diff --git a/Project.toml b/Project.toml index dab1df7e3..9637847ec 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ArrayInterface" uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9" -version = "3.0.0" +version = "3.0.1" [deps] IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173" diff --git a/src/ArrayInterface.jl b/src/ArrayInterface.jl index 14e200b14..7add18856 100644 --- a/src/ArrayInterface.jl +++ b/src/ArrayInterface.jl @@ -744,8 +744,8 @@ end include("static.jl") include("ranges.jl") -include("dimensions.jl") include("indexing.jl") +include("dimensions.jl") include("stridelayout.jl") function __init__() diff --git a/src/dimensions.jl b/src/dimensions.jl index ea39449ab..7220d78e4 100644 --- a/src/dimensions.jl +++ b/src/dimensions.jl @@ -246,6 +246,27 @@ end @inline function axes_types(::Type{T}) where {P,I,T<:SubArray{<:Any,<:Any,P,I}} return _sub_axes_types(Val(ArrayStyle(T)), I, axes_types(P)) end +@inline function axes_types(::Type{T}) where {T<:Base.ReinterpretArray} + return _reinterpret_axes_types( + axes_types(parent_type(T)), + eltype(T), + eltype(parent_type(T)), + ) +end +function axes_types(::Type{T}) where {N,T<:Base.ReshapedArray{<:Any,N}} + return Tuple{Vararg{OptionallyStaticUnitRange{One,Int},N}} +end + +# These methods help handle identifying axes that don't directly propagate from the +# parent array axes. They may be worth making a formal part of the API, as they provide +# a low traffic spot to change what axes_types produces. +@inline function sub_axis_type(::Type{A}, ::Type{I}) where {A,I} + if known_length(I) === nothing + return OptionallyStaticUnitRange{One,Int} + else + return OptionallyStaticUnitRange{One,StaticInt{known_length(I)}} + end +end @generated function _sub_axes_types( ::Val{S}, ::Type{I}, @@ -264,13 +285,15 @@ end end Expr(:block, Expr(:meta, :inline), out) end - -@inline function axes_types(::Type{T}) where {T<:Base.ReinterpretArray} - return _reinterpret_axes_types( - axes_types(parent_type(T)), - eltype(T), - eltype(parent_type(T)), - ) +@inline function reinterpret_axis_type(::Type{A}, ::Type{T}, ::Type{S}) where {A,T,S} + if known_length(A) === nothing + return OptionallyStaticUnitRange{One,Int} + else + return OptionallyStaticUnitRange{ + One, + StaticInt{Int(known_length(A) / (sizeof(T) / sizeof(S)))}, + } + end end @generated function _reinterpret_axes_types( ::Type{I}, @@ -288,9 +311,6 @@ end Expr(:block, Expr(:meta, :inline), out) end -function axes_types(::Type{T}) where {N,T<:Base.ReshapedArray{<:Any,N}} - return Tuple{Vararg{OptionallyStaticUnitRange{One,Int},N}} -end """ diff --git a/src/stridelayout.jl b/src/stridelayout.jl index 7e418d38c..5527b5929 100644 --- a/src/stridelayout.jl +++ b/src/stridelayout.jl @@ -313,27 +313,7 @@ end _known_length(::Nothing, _, __) = nothing @inline _known_length(L::Integer, ::Type{T}, ::Type{P}) where {T,P} = L * sizeof(P) รท sizeof(T) -# These methods help handle identifying axes that dont' directly propagate from the -# parent array axes. They may be worth making a formal part of the API, as they provide -# a low traffic spot to change what axes_types produces. -@inline function sub_axis_type(::Type{A}, ::Type{I}) where {A,I} - if known_length(I) === nothing - return OptionallyStaticUnitRange{One,Int} - else - return OptionallyStaticUnitRange{One,StaticInt{known_length(I)}} - end -end -@inline function reinterpret_axis_type(::Type{A}, ::Type{T}, ::Type{S}) where {A,T,S} - if known_length(A) === nothing - return OptionallyStaticUnitRange{One,Int} - else - return OptionallyStaticUnitRange{ - One, - StaticInt{Int(known_length(A) / (sizeof(T) / sizeof(S)))}, - } - end -end """ known_offsets(::Type{T}[, d]) -> Tuple