1
1
# Infinite Arrays implementation from
2
2
# https://github.com/JuliaLang/julia/blob/master/test/testhelpers/InfiniteArrays.jl
3
3
module InfiniteArrays
4
- export OneToInf, Infinity
5
-
6
- """
7
- Infinity()
8
- Represents infinite cardinality. Note that `Infinity <: Integer` to support
9
- being treated as an index.
10
- """
11
- struct Infinity <: Integer end
12
-
13
- Base.:(== )(:: Infinity , :: Int ) = false
14
- Base.:(== )(:: Int , :: Infinity ) = false
15
- Base.:(< )(:: Int , :: Infinity ) = true
16
- Base.:(< )(:: Infinity , :: Int ) = false
17
- Base.:(≤ )(:: Int , :: Infinity ) = true
18
- Base.:(≤ )(:: Infinity , :: Int ) = false
19
- Base.:(≤ )(:: Infinity , :: Infinity ) = true
20
- Base.:(- )(:: Infinity , :: Int ) = Infinity ()
21
- Base.:(+ )(:: Infinity , :: Int ) = Infinity ()
22
- Base.:(:)(:: Infinity , :: Infinity ) = 1 : 0
23
-
24
- Base.:(+ )(:: Integer , :: Infinity ) = Infinity ()
25
- Base.:(+ )(:: Infinity , :: Integer ) = Infinity ()
26
- Base.:(* )(:: Integer , :: Infinity ) = Infinity ()
27
- Base.:(* )(:: Infinity , :: Integer ) = Infinity ()
28
-
29
- Base. isinf (:: Infinity ) = true
4
+ using Infinities
5
+ export OneToInf
30
6
31
7
abstract type AbstractInfUnitRange{T<: Real } <: AbstractUnitRange{T} end
32
- Base. length (r:: AbstractInfUnitRange ) = Infinity ()
33
- Base. size (r:: AbstractInfUnitRange ) = (Infinity (),)
34
- Base. unitrange (r:: AbstractInfUnitRange ) = InfUnitRange (r)
35
- Base. last (r:: AbstractInfUnitRange ) = Infinity ()
8
+ Base. length (r:: AbstractInfUnitRange ) = ℵ₀
9
+ Base. size (r:: AbstractInfUnitRange ) = (ℵ₀,)
10
+ Base. last (r:: AbstractInfUnitRange ) = ℵ₀
36
11
Base. axes (r:: AbstractInfUnitRange ) = (OneToInf (),)
37
12
38
13
Base. IteratorSize (:: Type{<:AbstractInfUnitRange} ) = Base. IsInfinite ()
@@ -49,7 +24,7 @@ module InfiniteArrays
49
24
50
25
Base. axes (r:: OneToInf ) = (r,)
51
26
Base. first (r:: OneToInf{T} ) where {T} = oneunit (T)
52
- Base. oneto (:: Infinity ) = OneToInf ()
27
+ Base. oneto (:: InfiniteCardinal{0} ) = OneToInf ()
53
28
54
29
struct InfUnitRange{T<: Real } <: AbstractInfUnitRange{T}
55
30
start:: T
@@ -58,8 +33,7 @@ module InfiniteArrays
58
33
InfUnitRange (a:: InfUnitRange ) = a
59
34
InfUnitRange {T} (a:: AbstractInfUnitRange ) where T<: Real = InfUnitRange {T} (first (a))
60
35
InfUnitRange (a:: AbstractInfUnitRange{T} ) where T<: Real = InfUnitRange {T} (first (a))
61
- unitrange (a:: AbstractInfUnitRange ) = InfUnitRange (a)
62
- Base.:(:)(start:: T , stop:: Infinity ) where {T<: Integer } = InfUnitRange {T} (start)
36
+ Base.:(:)(start:: T , stop:: InfiniteCardinal{0} ) where {T<: Integer } = InfUnitRange {T} (start)
63
37
function getindex (v:: InfUnitRange{T} , i:: Integer ) where T
64
38
@boundscheck i > 0 || Base. throw_boundserror (v, i)
65
39
convert (T, first (v) + i - 1 )
0 commit comments