Skip to content

Commit 090dab9

Browse files
committed
Static -> StaticInt.
1 parent 42258b5 commit 090dab9

File tree

5 files changed

+122
-121
lines changed

5 files changed

+122
-121
lines changed

src/ArrayInterface.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -741,14 +741,14 @@ function __init__()
741741
@generated function size(A::StaticArrays.StaticArray{S}) where {S}
742742
t = Expr(:tuple); Sp = S.parameters
743743
for n in 1:length(Sp)
744-
push!(t.args, Expr(:call, Expr(:curly, :Static, Sp[n])))
744+
push!(t.args, Expr(:call, Expr(:curly, :StaticInt, Sp[n])))
745745
end
746746
t
747747
end
748748
@generated function strides(A::StaticArrays.StaticArray{S}) where {S}
749-
t = Expr(:tuple, Expr(:call, Expr(:curly, :Static, 1))); Sp = S.parameters; x = 1
749+
t = Expr(:tuple, Expr(:call, Expr(:curly, :StaticInt, 1))); Sp = S.parameters; x = 1
750750
for n in 1:length(Sp)-1
751-
push!(t.args, Expr(:call, Expr(:curly, :Static, (x *= Sp[n]))))
751+
push!(t.args, Expr(:call, Expr(:curly, :StaticInt, (x *= Sp[n]))))
752752
end
753753
t
754754
end

src/ranges.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,17 @@ struct OptionallyStaticUnitRange{F <: Integer, L <: Integer} <: AbstractUnitRang
7878
end
7979
end
8080

81-
Base.:(:)(L::Integer, ::Static{U}) where {U} = OptionallyStaticUnitRange(L, Static(U))
82-
Base.:(:)(::Static{L}, U::Integer) where {L} = OptionallyStaticUnitRange(Static(L), U)
83-
Base.:(:)(::Static{L}, ::Static{U}) where {L,U} = OptionallyStaticUnitRange(Static(L), Static(U))
81+
Base.:(:)(L::Integer, ::StaticInt{U}) where {U} = OptionallyStaticUnitRange(L, StaticInt(U))
82+
Base.:(:)(::StaticInt{L}, U::Integer) where {L} = OptionallyStaticUnitRange(StaticInt(L), U)
83+
Base.:(:)(::StaticInt{L}, ::StaticInt{U}) where {L,U} = OptionallyStaticUnitRange(StaticInt(L), StaticInt(U))
8484

8585
Base.first(r::OptionallyStaticUnitRange) = r.start
86-
Base.step(::OptionallyStaticUnitRange) = Static(1)
86+
Base.step(::OptionallyStaticUnitRange) = StaticInt(1)
8787
Base.last(r::OptionallyStaticUnitRange) = r.stop
8888

89-
known_first(::Type{<:OptionallyStaticUnitRange{Static{F}}}) where {F} = F
89+
known_first(::Type{<:OptionallyStaticUnitRange{StaticInt{F}}}) where {F} = F
9090
known_step(::Type{<:OptionallyStaticUnitRange}) = 1
91-
known_last(::Type{<:OptionallyStaticUnitRange{<:Any,Static{L}}}) where {L} = L
91+
known_last(::Type{<:OptionallyStaticUnitRange{<:Any,StaticInt{L}}}) where {L} = L
9292

9393
function Base.isempty(r::OptionallyStaticUnitRange)
9494
if known_first(r) === oneunit(eltype(r))
@@ -102,7 +102,7 @@ unsafe_isempty_one_to(lst) = lst <= zero(lst)
102102
unsafe_isempty_unit_range(fst, lst) = fst > lst
103103

104104
unsafe_length_one_to(lst::Int) = lst
105-
unsafe_length_one_to(::Static{L}) where {L} = lst
105+
unsafe_length_one_to(::StaticInt{L}) where {L} = lst
106106

107107
Base.@propagate_inbounds function Base.getindex(r::OptionallyStaticUnitRange, i::Integer)
108108
if known_first(r) === oneunit(r)
@@ -127,19 +127,19 @@ end
127127
return convert(eltype(r), val)
128128
end
129129

130-
@inline _try_static(::Static{N}, ::Static{N}) where {N} = Static{N}()
131-
@inline _try_static(::Static{M}, ::Static{N}) where {M, N} = @assert false "Unequal Indices: Static{$M}() != Static{$N}()"
132-
@propagate_inbounds function _try_static(::Static{N}, x) where {N}
130+
@inline _try_static(::StaticInt{N}, ::StaticInt{N}) where {N} = StaticInt{N}()
131+
@inline _try_static(::StaticInt{M}, ::StaticInt{N}) where {M, N} = @assert false "Unequal Indices: StaticInt{$M}() != StaticInt{$N}()"
132+
@propagate_inbounds function _try_static(::StaticInt{N}, x) where {N}
133133
@boundscheck begin
134-
@assert N == x "Unequal Indices: Static{$N}() != x == $x"
134+
@assert N == x "Unequal Indices: StaticInt{$N}() != x == $x"
135135
end
136-
return Static{N}()
136+
return StaticInt{N}()
137137
end
138-
@propagate_inbounds function _try_static(x, ::Static{N}) where {N}
138+
@propagate_inbounds function _try_static(x, ::StaticInt{N}) where {N}
139139
@boundscheck begin
140-
@assert N == x "Unequal Indices: x == $x != Static{$N}()"
140+
@assert N == x "Unequal Indices: x == $x != StaticInt{$N}()"
141141
end
142-
return Static{N}()
142+
return StaticInt{N}()
143143
end
144144
@propagate_inbounds function _try_static(x, y)
145145
@boundscheck begin

src/static.jl

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,95 @@
11

22
"""
33
A statically sized `Int`.
4-
Use `Static(N)` instead of `Val(N)` when you want it to behave like a number.
4+
Use `StaticInt(N)` instead of `Val(N)` when you want it to behave like a number.
55
"""
6-
struct Static{N} <: Integer
7-
Static{N}() where {N} = new{N::Int}()
6+
struct StaticInt{N} <: Integer
7+
StaticInt{N}() where {N} = new{N::Int}()
88
end
99

10-
const Zero = Static{0}
11-
const One = Static{1}
10+
const Zero = StaticInt{0}
11+
const One = StaticInt{1}
1212

13-
Base.@pure Static(N::Int) = Static{N}()
14-
Static(N::Integer) = Static(convert(Int, N))
15-
Static(::Static{N}) where {N} = Static{N}()
16-
Static(::Val{N}) where {N} = Static{N}()
17-
# Base.Val(::Static{N}) where {N} = Val{N}()
18-
Base.convert(::Type{T}, ::Static{N}) where {T<:Number,N} = convert(T, N)
19-
Base.convert(::Type{Static{N}}, ::Static{N}) where {N} = Static{N}()
13+
Base.@pure StaticInt(N::Int) = StaticInt{N}()
14+
StaticInt(N::Integer) = StaticInt(convert(Int, N))
15+
StaticInt(::StaticInt{N}) where {N} = StaticInt{N}()
16+
StaticInt(::Val{N}) where {N} = StaticInt{N}()
17+
# Base.Val(::StaticInt{N}) where {N} = Val{N}()
18+
Base.convert(::Type{T}, ::StaticInt{N}) where {T<:Number,N} = convert(T, N)
19+
# (::Type{T})(::ArrayInterface.StaticInt{N}) where {T,N} = T(N)
20+
Base.convert(::Type{StaticInt{N}}, ::StaticInt{N}) where {N} = StaticInt{N}()
2021

21-
Base.promote_rule(::Type{<:Static}, ::Type{T}) where {T <: AbstractIrrational} = promote_rule(Int, T)
22-
Base.promote_rule(::Type{T}, ::Type{<:Static}) where {T <: AbstractIrrational} = promote_rule(T, Int)
22+
Base.promote_rule(::Type{<:StaticInt}, ::Type{T}) where {T <: AbstractIrrational} = promote_rule(Int, T)
23+
Base.promote_rule(::Type{T}, ::Type{<:StaticInt}) where {T <: AbstractIrrational} = promote_rule(T, Int)
2324
for (S,T) [(:Complex,:Real), (:Rational, :Integer), (:(Base.TwicePrecision),:Any)]
24-
@eval Base.promote_rule(::Type{$S{T}}, ::Type{<:Static}) where {T <: $T} = promote_rule($S{T}, Int)
25+
@eval Base.promote_rule(::Type{$S{T}}, ::Type{<:StaticInt}) where {T <: $T} = promote_rule($S{T}, Int)
2526
end
26-
Base.promote_rule(::Type{Union{Nothing,Missing}}, ::Type{<:Static}) = Union{Nothing, Missing, Int}
27-
Base.promote_rule(::Type{T}, ::Type{<:Static}) where {T >: Union{Missing,Nothing}} = promote_rule(T, Int)
28-
Base.promote_rule(::Type{T}, ::Type{<:Static}) where {T >: Nothing} = promote_rule(T, Int)
29-
Base.promote_rule(::Type{T}, ::Type{<:Static}) where {T >: Missing} = promote_rule(T, Int)
27+
Base.promote_rule(::Type{Union{Nothing,Missing}}, ::Type{<:StaticInt}) = Union{Nothing, Missing, Int}
28+
Base.promote_rule(::Type{T}, ::Type{<:StaticInt}) where {T >: Union{Missing,Nothing}} = promote_rule(T, Int)
29+
Base.promote_rule(::Type{T}, ::Type{<:StaticInt}) where {T >: Nothing} = promote_rule(T, Int)
30+
Base.promote_rule(::Type{T}, ::Type{<:StaticInt}) where {T >: Missing} = promote_rule(T, Int)
3031
for T [:Bool, :Missing, :BigFloat, :BigInt, :Nothing, :Any]
3132
# let S = :Any
3233
@eval begin
33-
Base.promote_rule(::Type{S}, ::Type{$T}) where {S <: Static} = promote_rule(Int, $T)
34-
Base.promote_rule(::Type{$T}, ::Type{S}) where {S <: Static} = promote_rule($T, Int)
34+
Base.promote_rule(::Type{S}, ::Type{$T}) where {S <: StaticInt} = promote_rule(Int, $T)
35+
Base.promote_rule(::Type{$T}, ::Type{S}) where {S <: StaticInt} = promote_rule($T, Int)
3536
end
3637
end
37-
Base.promote_rule(::Type{<:Static}, ::Type{<:Static}) = Int
38-
Base.:(%)(::Static{N}, ::Type{Integer}) where {N} = N
38+
Base.promote_rule(::Type{<:StaticInt}, ::Type{<:StaticInt}) = Int
39+
Base.:(%)(::StaticInt{N}, ::Type{Integer}) where {N} = N
3940

40-
Base.eltype(::Type{T}) where {T<:Static} = Int
41+
Base.eltype(::Type{T}) where {T<:StaticInt} = Int
4142
Base.iszero(::Zero) = true
42-
Base.iszero(::Static) = false
43+
Base.iszero(::StaticInt) = false
4344
Base.isone(::One) = true
44-
Base.isone(::Static) = false
45-
Base.zero(::Type{T}) where {T<:Static} = Zero()
46-
Base.one(::Type{T}) where {T<:Static} = One()
45+
Base.isone(::StaticInt) = false
46+
Base.zero(::Type{T}) where {T<:StaticInt} = Zero()
47+
Base.one(::Type{T}) where {T<:StaticInt} = One()
4748

4849
for T = [:Real, :Rational, :Integer]
4950
@eval begin
5051
@inline Base.:(+)(i::$T, ::Zero) = i
51-
@inline Base.:(+)(i::$T, ::Static{M}) where {M} = i + M
52+
@inline Base.:(+)(i::$T, ::StaticInt{M}) where {M} = i + M
5253
@inline Base.:(+)(::Zero, i::$T) = i
53-
@inline Base.:(+)(::Static{M}, i::$T) where {M} = M + i
54+
@inline Base.:(+)(::StaticInt{M}, i::$T) where {M} = M + i
5455
@inline Base.:(-)(i::$T, ::Zero) = i
55-
@inline Base.:(-)(i::$T, ::Static{M}) where {M} = i - M
56+
@inline Base.:(-)(i::$T, ::StaticInt{M}) where {M} = i - M
5657
@inline Base.:(*)(i::$T, ::Zero) = Zero()
5758
@inline Base.:(*)(i::$T, ::One) = i
58-
@inline Base.:(*)(i::$T, ::Static{M}) where {M} = i * M
59+
@inline Base.:(*)(i::$T, ::StaticInt{M}) where {M} = i * M
5960
@inline Base.:(*)(::Zero, i::$T) = Zero()
6061
@inline Base.:(*)(::One, i::$T) = i
61-
@inline Base.:(*)(::Static{M}, i::$T) where {M} = M * i
62+
@inline Base.:(*)(::StaticInt{M}, i::$T) where {M} = M * i
6263
end
6364
end
6465
@inline Base.:(+)(::Zero, ::Zero) = Zero()
65-
@inline Base.:(+)(::Zero, ::Static{M}) where {M} = Static{M}()
66-
@inline Base.:(+)(::Static{M}, ::Zero) where {M} = Static{M}()
66+
@inline Base.:(+)(::Zero, ::StaticInt{M}) where {M} = StaticInt{M}()
67+
@inline Base.:(+)(::StaticInt{M}, ::Zero) where {M} = StaticInt{M}()
6768

68-
@inline Base.:(-)(::Static{M}, ::Zero) where {M} = Static{M}()
69+
@inline Base.:(-)(::StaticInt{M}, ::Zero) where {M} = StaticInt{M}()
6970

7071
@inline Base.:(*)(::Zero, ::Zero) = Zero()
7172
@inline Base.:(*)(::One, ::Zero) = Zero()
7273
@inline Base.:(*)(::Zero, ::One) = Zero()
7374
@inline Base.:(*)(::One, ::One) = One()
74-
@inline Base.:(*)(::Static{M}, ::Zero) where {M} = Zero()
75-
@inline Base.:(*)(::Zero, ::Static{M}) where {M} = Zero()
76-
@inline Base.:(*)(::Static{M}, ::One) where {M} = Static{M}()
77-
@inline Base.:(*)(::One, ::Static{M}) where {M} = Static{M}()
75+
@inline Base.:(*)(::StaticInt{M}, ::Zero) where {M} = Zero()
76+
@inline Base.:(*)(::Zero, ::StaticInt{M}) where {M} = Zero()
77+
@inline Base.:(*)(::StaticInt{M}, ::One) where {M} = StaticInt{M}()
78+
@inline Base.:(*)(::One, ::StaticInt{M}) where {M} = StaticInt{M}()
7879
for f [:(+), :(-), :(*), :(/), :(÷), :(%), :(<<), :(>>), :(>>>), :(&), :(|), :()]
79-
@eval @generated Base.$f(::Static{M}, ::Static{N}) where {M,N} = Expr(:call, Expr(:curly, :Static, $f(M, N)))
80+
@eval @generated Base.$f(::StaticInt{M}, ::StaticInt{N}) where {M,N} = Expr(:call, Expr(:curly, :StaticInt, $f(M, N)))
8081
end
8182
for f [:(==), :(!=), :(<), :(), :(>), :()]
8283
@eval begin
83-
@inline Base.$f(::Static{M}, ::Static{N}) where {M,N} = $f(M, N)
84-
@inline Base.$f(::Static{M}, x::Int) where {M} = $f(M, x)
85-
@inline Base.$f(x::Int, ::Static{M}) where {M} = $f(x, M)
84+
@inline Base.$f(::StaticInt{M}, ::StaticInt{N}) where {M,N} = $f(M, N)
85+
@inline Base.$f(::StaticInt{M}, x::Int) where {M} = $f(M, x)
86+
@inline Base.$f(x::Int, ::StaticInt{M}) where {M} = $f(x, M)
8687
end
8788
end
8889

8990
@inline function maybe_static(f::F, g::G, x) where {F, G}
9091
L = f(x)
91-
isnothing(L) ? g(x) : Static(L)
92+
isnothing(L) ? g(x) : StaticInt(L)
9293
end
9394
@inline static_length(x) = maybe_static(known_length, length, x)
9495
@inline static_first(x) = maybe_static(known_first, first, x)

src/stridelayout.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ julia> using StaticArrays, ArrayInterface
221221
julia> A = @SMatrix rand(3,4);
222222
223223
julia> ArrayInterface.size(A)
224-
(Static{3}(), Static{4}())
224+
(StaticInt{3}(), StaticInt{4}())
225225
```
226226
"""
227227
size(A) = Base.size(A)
@@ -234,7 +234,7 @@ these should be returned as `Static` numbers. For example:
234234
julia> A = rand(3,4);
235235
236236
julia> ArrayInterface.strides(A)
237-
(Static{1}(), 3)
237+
(StaticInt{1}(), 3)
238238
```
239239
"""
240240
strides(A) = Base.strides(A)
@@ -243,17 +243,17 @@ strides(A) = Base.strides(A)
243243
244244
Returns offsets of indices with respect to 0. If values are known at compile time,
245245
it should return them as `Static` numbers.
246-
For example, if `A isa Base.Matrix`, `offsets(A) === (Static(1), Static(1))`.
246+
For example, if `A isa Base.Matrix`, `offsets(A) === (StaticInt(1), StaticInt(1))`.
247247
"""
248-
offsets(::Any) = (Static{1}(),) # Assume arbitrary Julia data structures use 1-based indexing by default.
249-
@inline strides(A::Vector{<:Any}) = (Static(1),)
250-
@inline strides(A::Array{<:Any,N}) where {N} = (Static(1), Base.tail(Base.strides(A))...)
248+
offsets(::Any) = (StaticInt{1}(),) # Assume arbitrary Julia data structures use 1-based indexing by default.
249+
@inline strides(A::Vector{<:Any}) = (StaticInt(1),)
250+
@inline strides(A::Array{<:Any,N}) where {N} = (StaticInt(1), Base.tail(Base.strides(A))...)
251251
@inline strides(A::AbstractArray{<:Any,N}) where {N} = Base.strides(A)
252252

253253
@inline function offsets(x, i)
254254
inds = indices(x, i)
255255
start = known_first(inds)
256-
isnothing(start) ? first(inds) : Static(start)
256+
isnothing(start) ? first(inds) : StaticInt(start)
257257
end
258258
# @inline offsets(A::AbstractArray{<:Any,N}) where {N} = ntuple(n -> offsets(A, n), Val{N}())
259259
# Explicit tuple needed for inference.
@@ -267,11 +267,11 @@ end
267267

268268
@inline size(B::Union{Transpose{T,A},Adjoint{T,A}}) where {T,A<:AbstractMatrix{T}} = permute(size(parent(B)), Val{(2,1)}())
269269
@inline size(B::PermutedDimsArray{T,N,I1,I2,A}) where {T,N,I1,I2,A<:AbstractArray{T,N}} = permute(size(parent(B)), Val{I1}())
270-
@inline size(A::AbstractArray, ::Static{N}) where {N} = size(A)[N]
270+
@inline size(A::AbstractArray, ::StaticInt{N}) where {N} = size(A)[N]
271271
@inline size(A::AbstractArray, ::Val{N}) where {N} = size(A)[N]
272272
@inline strides(B::Union{Transpose{T,A},Adjoint{T,A}}) where {T,A<:AbstractMatrix{T}} = permute(strides(parent(B)), Val{(2,1)}())
273273
@inline strides(B::PermutedDimsArray{T,N,I1,I2,A}) where {T,N,I1,I2,A<:AbstractArray{T,N}} = permute(strides(parent(B)), Val{I1}())
274-
@inline stride(A::AbstractArray, ::Static{N}) where {N} = strides(A)[N]
274+
@inline stride(A::AbstractArray, ::StaticInt{N}) where {N} = strides(A)[N]
275275
@inline stride(A::AbstractArray, ::Val{N}) where {N} = strides(A)[N]
276276
stride(A, i) = Base.stride(A, i)
277277

0 commit comments

Comments
 (0)