Skip to content

Commit fc07935

Browse files
committed
Merge branch 'master' into subarrayofadjointvector
2 parents e0af2eb + afd0eac commit fc07935

File tree

7 files changed

+41
-10
lines changed

7 files changed

+41
-10
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ArrayInterface"
22
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
3-
version = "5.0.1"
3+
version = "5.0.5"
44

55
[deps]
66
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"

src/ArrayInterface.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import Compat
1313
using Base: @propagate_inbounds, tail, OneTo, LogicalIndex, Slice, ReinterpretArray,
1414
ReshapedArray, AbstractCartesianIndex
1515

16+
using Base.Iterators: Pairs
17+
1618
const CanonicalInt = Union{Int,StaticInt}
1719
canonicalize(x::Integer) = Int(x)
1820
canonicalize(@nospecialize(x::StaticInt)) = x
@@ -187,6 +189,11 @@ Query whether a type can use `setindex!`.
187189
can_setindex(x) = can_setindex(typeof(x))
188190
can_setindex(::Type) = true
189191
can_setindex(::Type{<:AbstractRange}) = false
192+
can_setindex(::Type{<:AbstractDict}) = true
193+
can_setindex(::Type{<:Base.ImmutableDict}) = false
194+
can_setindex(@nospecialize T::Type{<:Tuple}) = false
195+
can_setindex(@nospecialize T::Type{<:NamedTuple}) = false
196+
can_setindex(::Type{<:Pairs{<:Any,<:Any,P}}) where {P} = can_setindex(P)
190197

191198
"""
192199
aos_to_soa(x)

src/dimensions.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,15 @@ function to_parent_dims(::Type{T}, ::StaticInt{dim}) where {T,dim}
147147
end
148148
end
149149

150-
_nunderscore(::Val{N}) where {N} = ntuple(Compat.Returns(:_), Val(N))
151-
152150
"""
153151
has_dimnames(::Type{T}) -> StaticBool
154152
155153
Returns `static(true)` if `x` has on or more named dimensions. If all dimensions correspond
156154
to `static(:_)`, then `static(false)` is returned.
157155
"""
158-
Compat.@constprop :aggressive has_dimnames(x) = static(_is_named(known_dimnames(x)))
159-
_is_named(x::NTuple{N,Symbol}) where {N} = x !== _nunderscore(Val(N))
160-
_is_named(::Any) = true
156+
@inline function has_dimnames(x)
157+
static(known_dimnames(x) !== ntuple(Compat.Returns(:_), Val(ndims(x))))
158+
end
161159

162160
"""
163161
known_dimnames(::Type{T}) -> Tuple{Vararg{Union{Symbol,Nothing}}}
@@ -170,7 +168,7 @@ have a name.
170168
known_dimnames(x) = known_dimnames(typeof(x))
171169
known_dimnames(::Type{T}) where {T} = _known_dimnames(T, parent_type(T))
172170
_known_dimnames(::Type{T}, ::Type{T}) where {T} = _unknown_dimnames(Base.IteratorSize(T))
173-
_unknown_dimnames(::Base.HasShape{N}) where {N} = _nunderscore(Val(N))
171+
_unknown_dimnames(::Base.HasShape{N}) where {N} = ntuple(Compat.Returns(:_), Val(N))
174172
_unknown_dimnames(::Any) = (:_,)
175173
function _known_dimnames(::Type{C}, ::Type{P}) where {C,P}
176174
eachop(_inbounds_known_dimname, to_parent_dims(C), known_dimnames(P))

src/ranges.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,19 @@ Returns valid indices for array `x` along each dimension specified in `dim`.
482482
_indices(x, dims::Tuple) = (indices(x, first(dims)), _indices(x, tail(dims))...)
483483
_indices(x, ::Tuple{}) = ()
484484

485+
function Base.Broadcast.axistype(r::OptionallyStaticUnitRange{StaticInt{1}}, _)
486+
Base.OneTo(last(r))
487+
end
488+
function Base.Broadcast.axistype(_, r::OptionallyStaticUnitRange{StaticInt{1}})
489+
Base.OneTo(last(r))
490+
end
491+
function Base.Broadcast.axistype(r::OptionallyStaticUnitRange{StaticInt{1}}, ::OptionallyStaticUnitRange{StaticInt{1}})
492+
Base.OneTo(last(r))
493+
end
494+
function Base.similar(::Type{<:Array{T}}, axes::Tuple{OptionallyStaticUnitRange{StaticInt{1}},Vararg{Union{Base.OneTo,OptionallyStaticUnitRange{StaticInt{1}}}}}) where {T}
495+
Array{T}(undef, map(last, axes))
496+
end
497+
function Base.similar(::Type{<:Array{T}}, axes::Tuple{Base.OneTo,OptionallyStaticUnitRange{StaticInt{1}},Vararg{Union{Base.OneTo,OptionallyStaticUnitRange{StaticInt{1}}}}}) where {T}
498+
Array{T}(undef, map(last, axes))
499+
end
500+

src/stridelayout.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function contiguous_axis(::Type{T}) where {T}
117117
return contiguous_axis(parent_type(T))
118118
end
119119
end
120-
contiguous_axis(::Type{<:Array}) = One()
120+
contiguous_axis(::Type{<:DenseArray}) = One()
121121
contiguous_axis(::Type{<:BitArray}) = One()
122122
contiguous_axis(::Type{<:AbstractRange}) = One()
123123
contiguous_axis(::Type{<:Tuple}) = One()
@@ -220,7 +220,7 @@ function stride_rank(::Type{T}) where {T}
220220
return stride_rank(parent_type(T))
221221
end
222222
end
223-
stride_rank(::Type{Array{T,N}}) where {T,N} = nstatic(Val(N))
223+
stride_rank(::Type{<:DenseArray{T,N}}) where {T,N} = nstatic(Val(N))
224224
stride_rank(::Type{BitArray{N}}) where {N} = nstatic(Val(N))
225225
stride_rank(::Type{<:AbstractRange}) = (One(),)
226226
stride_rank(::Type{<:Tuple}) = (One(),)

test/ranges.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@
118118
@test @inferred(eachindex(static(-7):static(7))) === static(1):static(15)
119119
@test @inferred((static(-7):static(7))[first(eachindex(static(-7):static(7)))]) == -7
120120

121-
@test @inferred(firstindex(128:static(-1):1)) == 1
121+
@test @inferred(firstindex(128:static(-1):1)) == 1
122+
123+
@test identity.(static(1):5) isa Vector{Int}
124+
@test (static(1):5) .+ (1:3)' isa Matrix{Int}
125+
@test similar(Array{Int}, (static(1):(4),)) isa Vector{Int}
126+
@test similar(Array{Int}, (static(1):(4), Base.OneTo(4))) isa Matrix{Int}
127+
@test similar(Array{Int}, (Base.OneTo(4), static(1):(4))) isa Matrix{Int}
122128
end
123129

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ end
7272
@test !@inferred(ArrayInterface.can_setindex(1:2))
7373
@test @inferred(ArrayInterface.can_setindex(Vector{Int}))
7474
@test !@inferred(ArrayInterface.can_setindex(UnitRange{Int}))
75+
@test !@inferred(ArrayInterface.can_setindex(Base.ImmutableDict{Int,Int}))
76+
@test !@inferred(ArrayInterface.can_setindex(Tuple{}))
77+
@test !@inferred(ArrayInterface.can_setindex(NamedTuple{(),Tuple{}}))
78+
@test @inferred(ArrayInterface.can_setindex(Dict{Int,Int}))
7579
end
7680

7781
@testset "ArrayInterface.isstructured" begin

0 commit comments

Comments
 (0)