@@ -61,6 +61,16 @@ struct StaticInt{N} <: StaticInteger{N}
61
61
StaticInt (:: Val{N} ) where {N} = StaticInt (N)
62
62
end
63
63
64
+ """
65
+ IntType(x::Integer) -> Union{Int,StaticInt}
66
+
67
+ `IntType` is a union of `Int` and `StaticInt`. As a function, it ensures that `x` one of the
68
+ two.
69
+ """
70
+ const IntType = Union{StaticInt, Int}
71
+ IntType (x:: Integer ) = Int (x)
72
+ IntType (@nospecialize x:: Union{Int, StaticInt} ) = x
73
+
64
74
include (" float.jl" )
65
75
66
76
const StaticNumber{N} = Union{StaticInt{N}, StaticBool{N}, StaticFloat64{N}}
@@ -260,6 +270,36 @@ _static_promote(::Nothing, ::Nothing) = nothing
260
270
_static_promote (x, :: Nothing ) = x
261
271
_static_promote (:: Nothing , y) = y
262
272
273
+ """
274
+ static_promote(x::AbstractRange{<:Integer}, y::AbstractRange{<:Integer})
275
+
276
+ A type stable method for combining two equal ranges into a new range that preserves static
277
+ parameters. Throws an error if `x != y`.
278
+
279
+ # Examples
280
+
281
+ ```julia
282
+ julia> static_promote(static(1):10, 1:static(10))
283
+ static(1):static(10)
284
+
285
+ julia> static_promote(1:2:9, static(1):static(2):static(9))
286
+ static(1):static(2):static(9)
287
+ ```
288
+ """
289
+ Base. @propagate_inbounds @inline function static_promote (x:: AbstractUnitRange{<:Integer} ,
290
+ y:: AbstractUnitRange{<:Integer} )
291
+ fst = static_promote (static_first (x), static_first (y))
292
+ lst = static_promote (static_last (x), static_last (y))
293
+ return OptionallyStaticUnitRange (fst, lst)
294
+ end
295
+ Base. @propagate_inbounds @inline function static_promote (x:: AbstractRange{<:Integer} ,
296
+ y:: AbstractRange{<:Integer} )
297
+ fst = static_promote (static_first (x), static_first (y))
298
+ stp = static_promote (static_step (x), static_step (y))
299
+ lst = static_promote (static_last (x), static_last (y))
300
+ return _OptionallyStaticStepRange (fst, stp, lst)
301
+ end
302
+
263
303
Base. @propagate_inbounds function _promote_shape (a:: Tuple{A, Vararg{Any}} ,
264
304
b:: Tuple{B, Vararg{Any}} ) where {A, B}
265
305
(static_promote (getfield (a, 1 ), getfield (b, 1 )),
@@ -879,4 +919,6 @@ function Base.show(io::IO, m::MIME"text/plain", @nospecialize(x::NDIndex))
879
919
nothing
880
920
end
881
921
922
+ include (" ranges.jl" )
923
+
882
924
end
0 commit comments