Skip to content

Commit f309f48

Browse files
Merge pull request #300 from JuliaArrays/ChrisRackauckas-patch-1
Test Static 0.7
2 parents 747ebd3 + 19bfb47 commit f309f48

File tree

12 files changed

+49
-59
lines changed

12 files changed

+49
-59
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
1313
ArrayInterfaceCore = "0.1.3"
1414
Compat = "3, 4"
1515
IfElse = "0.1"
16-
Static = "0.6"
16+
Static = "0.7"
1717
julia = "1.6"
1818

1919
[extras]

lib/ArrayInterfaceOffsetArrays/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ArrayInterfaceOffsetArrays"
22
uuid = "015c0d05-e682-4f19-8f0a-679ce4c54826"
3-
version = "0.1.5"
3+
version = "0.1.6"
44

55
[deps]
66
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
@@ -10,7 +10,7 @@ Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
1010
[compat]
1111
ArrayInterface = "5, 6"
1212
OffsetArrays = "1.11"
13-
Static = "0.6"
13+
Static = "0.7"
1414
julia = "1.6"
1515

1616
[extras]

lib/ArrayInterfaceOffsetArrays/src/ArrayInterfaceOffsetArrays.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ function _offset_axis_type(::Type{T}, dim::StaticInt{D}) where {T,D}
2525
OffsetArrays.IdOffsetRange{Int,ArrayInterface.axes_types(T, dim)}
2626
end
2727
function ArrayInterface.axes_types(::Type{T}) where {T<:OffsetArrays.OffsetArray}
28-
Static.eachop_tuple(_offset_axis_type, Static.nstatic(Val(ndims(T))), ArrayInterface.parent_type(T))
28+
Static.eachop_tuple(
29+
_offset_axis_type,
30+
ntuple(static, StaticInt(ndims(T))),
31+
ArrayInterface.parent_type(T)
32+
)
2933
end
3034
ArrayInterface.strides(A::OffsetArray) = ArrayInterface.strides(parent(A))
3135
function ArrayInterface.known_offsets(::Type{A}) where {A<:OffsetArrays.OffsetArray}

lib/ArrayInterfaceStaticArrays/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ArrayInterfaceStaticArrays"
22
uuid = "b0d46f97-bff5-4637-a19a-dd75974142cd"
3-
version = "0.1.2"
3+
version = "0.1.3"
44

55
[deps]
66
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
@@ -12,7 +12,7 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1212
[compat]
1313
Adapt = "3"
1414
ArrayInterface = "6"
15-
Static = "0.6"
15+
Static = "0.7"
1616
StaticArrays = "1.2.5, 1.3, 1.4"
1717
julia = "1.6"
1818

lib/ArrayInterfaceStaticArrays/src/ArrayInterfaceStaticArrays.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ ArrayInterface.device(::Type{<:StaticArrays.MArray}) = ArrayInterface.CPUPointer
4040
ArrayInterface.device(::Type{<:StaticArrays.SArray}) = ArrayInterface.CPUTuple()
4141
ArrayInterface.contiguous_axis(::Type{<:StaticArrays.StaticArray}) = StaticInt{1}()
4242
ArrayInterface.contiguous_batch_size(::Type{<:StaticArrays.StaticArray}) = StaticInt{0}()
43-
ArrayInterface.stride_rank(::Type{T}) where {N,T<:StaticArray{<:Any,<:Any,N}} = Static.nstatic(Val(N))
43+
function ArrayInterface.stride_rank(::Type{T}) where {N,T<:StaticArray{<:Any,<:Any,N}}
44+
ntuple(static, StaticInt(N))
45+
end
4446
function ArrayInterface.dense_dims(::Type{<:StaticArray{S,T,N}}) where {S,T,N}
4547
ArrayInterface._all_dense(Val(N))
4648
end

src/axes.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ end
6565
end
6666

6767
function axes_types(::Type{T}) where {T<:ReinterpretArray}
68-
eachop_tuple(_non_reshaped_axis_type, nstatic(Val(ndims(T))), T)
68+
eachop_tuple(_non_reshaped_axis_type, ntuple(static, StaticInt(ndims(T))), T)
6969
end
7070

7171
function _non_reshaped_axis_type(::Type{A}, d::StaticInt{D}) where {A,D}
@@ -146,7 +146,7 @@ function axes_types(::Type{A}) where {T,N,S,A<:Base.ReshapedReinterpretArray{T,N
146146
return merge_tuple_type(Tuple{SOneTo{div(sizeof(S), sizeof(T))}}, axes_types(parent_type(A)))
147147
elseif sizeof(S) < sizeof(T)
148148
P = parent_type(A)
149-
return eachop_tuple(field_type, tail(nstatic(Val(ndims(P)))), axes_types(P))
149+
return eachop_tuple(field_type, tail(ntuple(static, StaticInt(ndims(P)))), axes_types(P))
150150
else
151151
return axes_types(parent_type(A))
152152
end
@@ -241,9 +241,10 @@ Base.axes1(x::LazyAxis) = x
241241
Base.axes(x::Slice{<:LazyAxis}) = (Base.axes1(x),)
242242
# assuming that lazy loaded params like dynamic length from `size(::Array, dim)` are going
243243
# be used again later with `Slice{LazyAxis}`, we quickly load indices
244+
244245
Base.axes1(x::Slice{LazyAxis{N,A}}) where {N,A} = indices(getfield(x.indices, :parent), StaticInt(N))
245246
Base.axes1(x::Slice{LazyAxis{:,A}}) where {A} = indices(getfield(x.indices, :parent))
246-
Base.to_shape(x::LazyAxis) = length(x)
247+
Base.to_shape(x::LazyAxis) = Base.length(x)
247248

248249
@propagate_inbounds function Base.getindex(x::LazyAxis, i::CanonicalInt)
249250
@boundscheck checkindex(Bool, x, i) || throw(BoundsError(x, i))

src/dimensions.jl

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,6 @@ function throw_dim_error(@nospecialize(x), @nospecialize(dim))
33
throw(DimensionMismatch("$x does not have dimension corresponding to $dim"))
44
end
55

6-
@propagate_inbounds function _promote_shape(a::Tuple{A,Vararg{Any}}, b::Tuple{B,Vararg{Any}}) where {A,B}
7-
(_try_static(getfield(a, 1), getfield(b, 1)), _promote_shape(tail(a), tail(b))...)
8-
end
9-
_promote_shape(::Tuple{}, ::Tuple{}) = ()
10-
@propagate_inbounds function _promote_shape(::Tuple{}, b::Tuple{B}) where {B}
11-
(_try_static(static(1), getfield(b, 1)),)
12-
end
13-
@propagate_inbounds function _promote_shape(a::Tuple{A}, ::Tuple{}) where {A}
14-
(_try_static(static(1), getfield(a, 1)),)
15-
end
16-
@propagate_inbounds function Base.promote_shape(a::Tuple{Vararg{CanonicalInt}}, b::Tuple{Vararg{CanonicalInt}})
17-
_promote_shape(a, b)
18-
end
19-
20-
#julia> @btime ArrayInterfaceCore.is_increasing(ArrayInterfaceCore.nstatic(Val(10)))
21-
# 0.045 ns (0 allocations: 0 bytes)
22-
#ArrayInterfaceCore.True()
236
function is_increasing(perm::Tuple{StaticInt{X},StaticInt{Y},Vararg}) where {X, Y}
247
if X <= Y
258
return is_increasing(tail(perm))
@@ -44,7 +27,7 @@ is_increasing(::Tuple{}) = True()
4427
Returns the mapping from parent dimensions to child dimensions.
4528
"""
4629
from_parent_dims(x) = from_parent_dims(typeof(x))
47-
from_parent_dims(::Type{T}) where {T} = nstatic(Val(ndims(T)))
30+
from_parent_dims(::Type{T}) where {T} = ntuple(static, StaticInt(ndims(T)))
4831
from_parent_dims(::Type{T}) where {T<:VecAdjTrans} = (StaticInt(2),)
4932
from_parent_dims(::Type{T}) where {T<:MatAdjTrans} = (StaticInt(2), One())
5033
from_parent_dims(::Type{<:SubArray{T,N,A,I}}) where {T,N,A,I} = _from_sub_dims(I)
@@ -65,11 +48,11 @@ end
6548
from_parent_dims(::Type{<:PermutedDimsArray{T,N,<:Any,I}}) where {T,N,I} = static(Val(I))
6649
function from_parent_dims(::Type{<:ReinterpretArray{T,N,S,A,IsReshaped}}) where {T,N,S,A,IsReshaped}
6750
if !IsReshaped || sizeof(S) === sizeof(T)
68-
return nstatic(Val(ndims(A)))
51+
return ntuple(static, StaticInt(ndims(A)))
6952
elseif sizeof(S) > sizeof(T)
70-
return tail(nstatic(Val(ndims(A) + 1)))
53+
return tail(ntuple(static, StaticInt(ndims(A) + 1)))
7154
else # sizeof(S) < sizeof(T)
72-
return (Zero(), nstatic(Val(N))...)
55+
return (Zero(), ntuple(static, StaticInt(N))...)
7356
end
7457
end
7558

@@ -100,7 +83,7 @@ end
10083
Returns the mapping from child dimensions to parent dimensions.
10184
"""
10285
to_parent_dims(x) = to_parent_dims(typeof(x))
103-
to_parent_dims(::Type{T}) where {T} = nstatic(Val(ndims(T)))
86+
to_parent_dims(::Type{T}) where {T} = ntuple(static, StaticInt(ndims(T)))
10487
to_parent_dims(::Type{T}) where {T<:Union{Transpose,Adjoint}} = (StaticInt(2), One())
10588
to_parent_dims(::Type{<:PermutedDimsArray{T,N,I}}) where {T,N,I} = static(Val(I))
10689
to_parent_dims(::Type{<:SubArray{T,N,A,I}}) where {T,N,A,I} = _to_sub_dims(I)
@@ -117,7 +100,7 @@ to_parent_dims(::Type{<:SubArray{T,N,A,I}}) where {T,N,A,I} = _to_sub_dims(I)
117100
out
118101
end
119102
function to_parent_dims(::Type{<:ReinterpretArray{T,N,S,A,IsReshaped}}) where {T,N,S,A,IsReshaped}
120-
pdims = nstatic(Val(ndims(A)))
103+
pdims = ntuple(static, StaticInt(ndims(A)))
121104
if !IsReshaped || sizeof(S) === sizeof(T)
122105
return pdims
123106
elseif sizeof(S) > sizeof(T)
@@ -280,7 +263,7 @@ to_dims(x, @nospecialize(dim::CanonicalInt)) = dim
280263
to_dims(x, dim::Integer) = Int(dim)
281264
to_dims(x, dim::Union{StaticSymbol,Symbol}) = _to_dim(dimnames(x), dim)
282265
function to_dims(x, dims::Tuple{Vararg{Any,N}}) where {N}
283-
eachop(_to_dims, nstatic(Val(N)), dimnames(x), dims)
266+
eachop(_to_dims, ntuple(static, StaticInt(N)), dimnames(x), dims)
284267
end
285268
@inline _to_dims(x::Tuple, d::Tuple, n::StaticInt{N}) where {N} = _to_dim(x, getfield(d, N))
286269
@inline function _to_dim(x::Tuple, d::Union{Symbol,StaticSymbol})

src/indexing.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,9 @@ _ints2range_front(::Val{0}, ind, inds...) = ()
453453
_ints2range_front(::Val{0}) = ()
454454
# get output shape with given indices
455455
_output_shape(::CanonicalInt, inds...) = _output_shape(inds...)
456-
_output_shape(ind::AbstractRange, inds...) = (length(ind), _output_shape(inds...)...)
456+
_output_shape(ind::AbstractRange, inds...) = (Base.length(ind), _output_shape(inds...)...)
457457
_output_shape(::CanonicalInt) = ()
458-
_output_shape(x::AbstractRange) = (length(x),)
458+
_output_shape(x::AbstractRange) = (Base.length(x),)
459459
@inline function unsafe_get_collection(A::CartesianIndices{N}, inds) where {N}
460460
if (Base.length(inds) === 1 && N > 1) || stride_preserving_index(typeof(inds)) === False()
461461
return Base._getindex(IndexStyle(A), A, inds...)

src/ranges.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ function Base.iterate(::SOneTo{n}, s::Int) where {n}
294294
end
295295
end
296296

297-
Base.to_shape(x::OptionallyStaticRange) = length(x)
298-
Base.to_shape(x::Slice{T}) where {T<:OptionallyStaticRange} = length(x)
297+
Base.to_shape(x::OptionallyStaticRange) = Base.length(x)
298+
Base.to_shape(x::Slice{T}) where {T<:OptionallyStaticRange} = Base.length(x)
299299
Base.axes(S::Slice{<:OptionallyStaticUnitRange{One}}) = (S.indices,)
300300
Base.axes(S::Slice{<:OptionallyStaticRange}) = (Base.IdentityUnitRange(S.indices),)
301301

@@ -374,7 +374,7 @@ end
374374
Returns valid indices for each array in `x` along dimension `dim`
375375
"""
376376
@propagate_inbounds function indices(x::Tuple, dim)
377-
inds = map(x_i -> indices(x_i, dim), x)
377+
inds = map(Base.Fix2(indices, dim), x)
378378
return reduce_tup(_pick_range, inds)
379379
end
380380

src/size.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ size(x::Iterators.Enumerate) = size(getfield(x, :itr))
5656
size(x::Iterators.Accumulate) = size(getfield(x, :itr))
5757
size(x::Iterators.Pairs) = size(getfield(x, :itr))
5858
@inline function size(x::Iterators.ProductIterator)
59-
eachop(_sub_size, nstatic(Val(ndims(x))), getfield(x, :iterators))
59+
eachop(_sub_size, ntuple(static, StaticInt(ndims(x))), getfield(x, :iterators))
6060
end
6161

6262
size(a, dim) = size(a, to_dims(a, dim))
@@ -100,7 +100,7 @@ known_size(x) = known_size(typeof(x))
100100
end
101101
end
102102
function _maybe_known_size(::Base.HasShape{N}, ::Type{T}) where {N,T}
103-
eachop(_known_size, nstatic(Val(N)), axes_types(T))
103+
eachop(_known_size, ntuple(static, StaticInt(N)), axes_types(T))
104104
end
105105
_maybe_known_size(::Base.IteratorSize, ::Type{T}) where {T} = (known_length(T),)
106106
function known_size(::Type{T}) where {T<:AbstractRange}
@@ -113,7 +113,7 @@ known_size(::Type{<:Iterators.Enumerate{I}}) where {I} = known_size(I)
113113
known_size(::Type{<:Iterators.Accumulate{<:Any,I}}) where {I} = known_size(I)
114114
known_size(::Type{<:Iterators.Pairs{<:Any,<:Any,I}}) where {I} = known_size(I)
115115
@inline function known_size(::Type{<:Iterators.ProductIterator{T}}) where {T}
116-
eachop(_known_size, nstatic(Val(known_length(T))), T)
116+
eachop(_known_size, ntuple(static, StaticInt(known_length(T))), T)
117117
end
118118

119119
# 1. `Zip` doesn't check that its collections are compatible (same size) at construction,
@@ -123,7 +123,7 @@ end
123123
# trailing dimensions (which must be of size 1), to `static(1)`. We want to stick to
124124
# `Nothing` and `Int` types, so we do one last pass to ensure everything is dynamic
125125
@inline function known_size(::Type{<:Iterators.Zip{T}}) where {T}
126-
dynamic(reduce_tup(_promote_shape, eachop(_unzip_size, nstatic(Val(known_length(T))), T)))
126+
dynamic(reduce_tup(Static._promote_shape, eachop(_unzip_size, ntuple(static, StaticInt(known_length(T))), T)))
127127
end
128128
_unzip_size(::Type{T}, n::StaticInt{N}) where {T,N} = known_size(field_type(T, n))
129129
_known_size(::Type{T}, dim::StaticInt) where {T} = known_length(field_type(T, dim))

0 commit comments

Comments
 (0)