Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ArrayInterface"
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
version = "6.0.5"
version = "6.0.6"

[deps]
ArrayInterfaceCore = "30b0a656-2188-435a-8636-2ec0e6a096e2"
Expand Down
10 changes: 5 additions & 5 deletions src/ArrayInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ Base.@propagate_inbounds function insert(collection, index, item)
return ret
end

function insert(x::Tuple{Vararg{Any,N}}, index::Integer, item) where {N}
function insert(x::Tuple{Vararg{Any,N}}, index, item) where {N}
@boundscheck if !checkindex(Bool, StaticInt{1}():StaticInt{N}(), index)
throw(BoundsError(x, index))
end
Expand Down Expand Up @@ -229,7 +229,7 @@ Base.@propagate_inbounds function deleteat(collection::Tuple{Vararg{Any,N}}, ind
return unsafe_deleteat(collection, index)
end

function unsafe_deleteat(src::AbstractVector, index::Integer)
function unsafe_deleteat(src::AbstractVector, index)
dst = similar(src, length(src) - 1)
@inbounds for i in indices(dst)
if i < index
Expand Down Expand Up @@ -265,10 +265,10 @@ end
return Tuple(dst)
end

@inline unsafe_deleteat(x::Tuple{T}, i::Integer) where {T} = ()
@inline unsafe_deleteat(x::Tuple{T1,T2}, i::Integer) where {T1,T2} =
@inline unsafe_deleteat(x::Tuple{T}, i) where {T} = ()
@inline unsafe_deleteat(x::Tuple{T1,T2}, i) where {T1,T2} =
isone(i) ? (x[2],) : (x[1],)
@inline function unsafe_deleteat(x::Tuple, i::Integer)
@inline function unsafe_deleteat(x::Tuple, i)
if i === one(i)
return tail(x)
elseif i == length(x)
Expand Down
8 changes: 3 additions & 5 deletions src/axes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ end
end
end

@inline function axes(A::SubArray, dim::Integer)
@inline function axes(A::SubArray, dim::CanonicalInt)
if dim > ndims(A)
return OneTo(1)
else
Expand Down Expand Up @@ -260,15 +260,15 @@ Base.axes(x::Slice{<:LazyAxis}) = (Base.axes1(x),)
Base.axes1(x::Slice{<:LazyAxis}) = indices(parent(x.indices))
Base.to_shape(x::LazyAxis) = length(x)

@inline function Base.checkindex(::Type{Bool}, x::LazyAxis, i::Integer)
@inline function Base.checkindex(::Type{Bool}, x::LazyAxis, i::CanonicalInt)
if known_first(x) === nothing || known_last(x) === nothing
return checkindex(Bool, parent(x), i)
else # everything is static so we don't have to retrieve the axis
return (!(known_first(x) > i) || !(known_last(x) < i))
end
end

@propagate_inbounds function Base.getindex(x::LazyAxis, i::Integer)
@propagate_inbounds function Base.getindex(x::LazyAxis, i::CanonicalInt)
@boundscheck checkindex(Bool, x, i) || throw(BoundsError(x, i))
return Int(i)
end
Expand All @@ -294,5 +294,3 @@ lazy_axes(x::CartesianIndices) = axes(x)
@inline lazy_axes(x::MatAdjTrans) = reverse(lazy_axes(parent(x)))
@inline lazy_axes(x::VecAdjTrans) = (SOneTo{1}(), first(lazy_axes(parent(x))))
@inline lazy_axes(x::PermutedDimsArray) = permute(lazy_axes(parent(x)), to_parent_dims(x))


12 changes: 6 additions & 6 deletions src/dimensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ from_parent_dims(::Type{<:SubArray{T,N,A,I}}) where {T,N,A,I} = _from_sub_dims(I
dim_i = 1
for i in 1:length(I.parameters)
p = I.parameters[i]
if p <: Integer
if p <: CanonicalInt
push!(out.args, :(StaticInt(0)))
else
push!(out.args, :(StaticInt($dim_i)))
Expand Down Expand Up @@ -107,7 +107,7 @@ to_parent_dims(::Type{<:SubArray{T,N,A,I}}) where {T,N,A,I} = _to_sub_dims(I)
out = Expr(:tuple)
n = 1
for p in I.parameters
if !(p <: Integer)
if !(p <: CanonicalInt)
push!(out.args, :(StaticInt($n)))
end
n += 1
Expand Down Expand Up @@ -161,7 +161,7 @@ to `:_`, then `false` is returned.
Return the names of the dimensions for `x`. `:_` is used to indicate a dimension does not
have a name.
"""
@inline known_dimnames(x, dim::Integer) = _known_dimname(known_dimnames(x), canonicalize(dim))
@inline known_dimnames(x, dim) = _known_dimname(known_dimnames(x), canonicalize(dim))
known_dimnames(x) = known_dimnames(typeof(x))
known_dimnames(::Type{T}) where {T} = _known_dimnames(T, parent_type(T))
_known_dimnames(::Type{T}, ::Type{T}) where {T} = _unknown_dimnames(Base.IteratorSize(T))
Expand All @@ -184,7 +184,7 @@ end
Return the names of the dimensions for `x`. `:_` is used to indicate a dimension does not
have a name.
"""
@inline dimnames(x, dim::Integer) = _dimname(dimnames(x), canonicalize(dim))
@inline dimnames(x, dim) = _dimname(dimnames(x), canonicalize(dim))
@inline dimnames(x) = _dimnames(has_parent(x), x)
@inline function _dimnames(::True, x)
eachop(_inbounds_dimname, to_parent_dims(x), dimnames(parent(x)))
Expand All @@ -204,7 +204,8 @@ end
This returns the dimension(s) of `x` corresponding to `dim`.
"""
to_dims(x, dim::Colon) = dim
to_dims(x, dim::Integer) = canonicalize(dim)
to_dims(x, @nospecialize(dim::CanonicalInt)) = dim
to_dims(x, dim::Integer) = Int(dim)
to_dims(x, dim::Union{StaticSymbol,Symbol}) = _to_dim(dimnames(x), dim)
function to_dims(x, dims::Tuple{Vararg{Any,N}}) where {N}
eachop(_to_dims, nstatic(Val(N)), dimnames(x), dims)
Expand Down Expand Up @@ -257,4 +258,3 @@ An error is thrown if any keywords are used which do not occur in `nda`'s names.
end
end
end

6 changes: 3 additions & 3 deletions src/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ This implementation differs from that of `Base.to_indices` in the following ways
* Specializing by dispatch through method definitions like this:
`to_indices(::ArrayType, ::Tuple{AxisType,Vararg{Any}}, ::Tuple{::IndexType,Vararg{Any}})`
require an excessive number of hand written methods to avoid ambiguities. Furthermore, if
`AxisType` is wrapping another axis that should have unique behavior, then unique parametric
`AxisType` is wrapping another axis that should have unique behavior, then unique parametric
types need to also be explicitly defined.
* `to_index(axes(A, dim), index)` is called, as opposed to `Base.to_index(A, index)`. The
`IndexStyle` of the resulting axis is used to allow indirect dispatch on nested axis types
Expand Down Expand Up @@ -228,7 +228,7 @@ indices calling [`to_axis`](@ref).
end
end
# drop this dimension
to_axes(A, a::Tuple, i::Tuple{<:Integer,Vararg{Any}}) = to_axes(A, tail(a), tail(i))
to_axes(A, a::Tuple, i::Tuple{<:CanonicalInt,Vararg{Any}}) = to_axes(A, tail(a), tail(i))
to_axes(A, a::Tuple, i::Tuple{I,Vararg{Any}}) where {I} = _to_axes(StaticInt(ndims_index(I)), A, a, i)
function _to_axes(::StaticInt{1}, A, axs::Tuple, inds::Tuple)
return (to_axis(first(axs), first(inds)), to_axes(A, tail(axs), tail(inds))...)
Expand Down Expand Up @@ -353,7 +353,7 @@ function unsafe_get_collection(A, inds)
end
return dest
end
_ints2range(x::Integer) = x:x
_ints2range(x::CanonicalInt) = x:x
_ints2range(x::AbstractRange) = x
@inline function unsafe_get_collection(A::CartesianIndices{N}, inds) where {N}
if (Base.length(inds) === 1 && N > 1) || stride_preserving_index(typeof(inds)) === False()
Expand Down
9 changes: 4 additions & 5 deletions src/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct OptionallyStaticUnitRange{F<:CanonicalInt,L<:CanonicalInt} <: AbstractUni
function OptionallyStaticUnitRange(start::CanonicalInt, stop::CanonicalInt)
new{typeof(start),typeof(stop)}(start, stop)
end
function OptionallyStaticUnitRange(start::Integer, stop::Integer)
function OptionallyStaticUnitRange(start, stop)
OptionallyStaticUnitRange(canonicalize(start), canonicalize(stop))
end
function OptionallyStaticUnitRange(x::AbstractRange)
Expand Down Expand Up @@ -60,7 +60,7 @@ struct OptionallyStaticStepRange{F<:CanonicalInt,S<:CanonicalInt,L<:CanonicalInt
lst = _steprange_last(start, step, stop)
new{typeof(start),typeof(step),typeof(lst)}(start, step, lst)
end
function OptionallyStaticStepRange(start::Integer, step::Integer, stop::Integer)
function OptionallyStaticStepRange(start, step, stop)
OptionallyStaticStepRange(canonicalize(start), canonicalize(step), canonicalize(stop))
end
function OptionallyStaticStepRange(x::AbstractRange)
Expand All @@ -72,15 +72,15 @@ end
@inline function _steprange_last(start::StaticInt, step::StaticInt, stop::StaticInt)
return StaticInt(_steprange_last(Int(start), Int(step), Int(stop)))
end
@inline function _steprange_last(start::Integer, step::StaticInt, stop::StaticInt)
@inline function _steprange_last(start, step::StaticInt, stop::StaticInt)
if step === one(step)
# we don't need to check the `stop` if we know it acts like a unit range
return stop
else
return _steprange_last(start, Int(step), Int(stop))
end
end
@inline function _steprange_last(start::Integer, step::Integer, stop::Integer)
@inline function _steprange_last(start, step, stop)
z = zero(step)
if step === z
throw(ArgumentError("step cannot be zero"))
Expand Down Expand Up @@ -415,4 +415,3 @@ end
function Base.similar(::Type{<:Array{T}}, axes::Tuple{Base.OneTo,OptionallyStaticUnitRange{StaticInt{1}},Vararg{Union{Base.OneTo,OptionallyStaticUnitRange{StaticInt{1}}}}}) where {T}
Array{T}(undef, map(last, axes))
end

7 changes: 3 additions & 4 deletions src/size.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ size(x::Iterators.Pairs) = size(getfield(x, :itr))
end

size(a, dim) = size(a, to_dims(a, dim))
size(a::Array, dim::Integer) = Base.arraysize(a, convert(Int, dim))
function size(a::A, dim::Integer) where {A}
size(a::Array, dim::CanonicalInt) = Base.arraysize(a, convert(Int, dim))
function size(a::A, dim::CanonicalInt) where {A}
if parent_type(A) <: A
len = known_size(A, dim)
if len === nothing
Expand All @@ -67,7 +67,7 @@ function size(a::A, dim::Integer) where {A}
return size(a)[dim]
end
end
function size(A::SubArray, dim::Integer)
function size(A::SubArray, dim::CanonicalInt)
pdim = to_parent_dims(A, dim)
if pdim > ndims(parent_type(A))
return size(parent(A), pdim)
Expand Down Expand Up @@ -170,4 +170,3 @@ _prod_or_nothing(_) = nothing

_maybe_known_length(::Base.HasShape, ::Type{T}) where {T} = _prod_or_nothing(known_size(T))
_maybe_known_length(::Base.IteratorSize, ::Type) = nothing

9 changes: 4 additions & 5 deletions src/stridelayout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ not known at compile time `nothing` is returned its position.
"""
known_offsets(x, dim) = known_offsets(typeof(x), dim)
known_offsets(::Type{T}, dim) where {T} = known_offsets(T, to_dims(T, dim))
function known_offsets(::Type{T}, dim::Integer) where {T}
function known_offsets(::Type{T}, dim::CanonicalInt) where {T}
if ndims(T) < dim
return 1
else
Expand Down Expand Up @@ -187,7 +187,7 @@ function _contiguous_axis(::Type{A}, c::StaticInt{C}) where {T,N,P,I,A<:SubArray
return from_parent_dims(A)[C]
elseif field_type(I, c) <: AbstractArray
return -One()
elseif field_type(I, c) <: Integer
elseif field_type(I, c) <: CanonicalInt
return -One()
else
return nothing
Expand Down Expand Up @@ -489,7 +489,7 @@ compile time are represented by `nothing`.
"""
known_strides(x, dim) = known_strides(typeof(x), dim)
known_strides(::Type{T}, dim) where {T} = known_strides(T, to_dims(T, dim))
function known_strides(::Type{T}, dim::Integer) where {T}
function known_strides(::Type{T}, dim::CanonicalInt) where {T}
# see https://github.com/JuliaLang/julia/blob/6468dcb04ea2947f43a11f556da9a5588de512a0/base/reinterpretarray.jl#L148
if ndims(T) < dim
return known_length(T)
Expand Down Expand Up @@ -663,7 +663,7 @@ maybe_static_step(_) = nothing
end

strides(a, dim) = strides(a, to_dims(a, dim))
function strides(a::A, dim::Integer) where {A}
function strides(a::A, dim::CanonicalInt) where {A}
if parent_type(A) <: A
return Base.stride(a, Int(dim))
else
Expand All @@ -674,4 +674,3 @@ end
@inline stride(A::AbstractArray, ::StaticInt{N}) where {N} = strides(A)[N]
@inline stride(A::AbstractArray, ::Val{N}) where {N} = strides(A)[N]
stride(A, i) = Base.stride(A, i) # for type stability