From 9fcbc1cfb689496a6aabf0e2cb01cbeaad46090c Mon Sep 17 00:00:00 2001 From: Tianyi Pu <912396513@qq.com> Date: Fri, 17 Mar 2023 08:50:49 +0000 Subject: [PATCH 1/2] last of InfStepRange should be RealInfinity --- src/infarrays.jl | 2 +- src/infrange.jl | 25 ++++--------------------- test/runtests.jl | 4 ++-- 3 files changed, 7 insertions(+), 24 deletions(-) diff --git a/src/infarrays.jl b/src/infarrays.jl index 9420a71..1a005dd 100644 --- a/src/infarrays.jl +++ b/src/infarrays.jl @@ -322,7 +322,7 @@ end # Concat: Hcat/Vcat ##### -function getindex(f::Vcat{T,1}, k::PosInfinity) where T +function getindex(f::Vcat{T,1}, k::InfiniteCardinal{0}) where T length(f) == ℵ₀ || throw(BoundsError(f,k)) ∞ end diff --git a/src/infrange.jl b/src/infrange.jl index ce4cf1e..cf240a6 100644 --- a/src/infrange.jl +++ b/src/infrange.jl @@ -204,29 +204,12 @@ function getindex(v::InfStepRange{T}, i::Integer) where T convert(T, first(v) + (i - 1)*step(v)) end -function getindex(x::AbstractUnitRange, y::PosInfinity) - isinf(length(x)) || throw(BoundsError(x,y)) - ℵ₀ -end - -function getindex(x::OneToInf{T}, y::PosInfinity) where T - isinf(length(x)) || throw(BoundsError(x,y)) - ℵ₀ -end +getindex(v::AbstractArray, i::Infinity) = v[Integer(i)] +getindex(v::AbstractArray, i::RealInfinity) = v[Integer(i)] -function getindex(x::InfStepRange{T}, y::PosInfinity) where T - isinf(length(x)) || throw(BoundsError(x,y)) - ℵ₀ +for infrange in (:AbstractInfUnitRange, :InfUnitRange, :OneToInf, :InfStepRange) + @eval getindex(v::$infrange, ::InfiniteCardinal{0}) = last(v) end -function getindex(x::InfUnitRange{T}, y::PosInfinity) where T - isinf(length(x)) || throw(BoundsError(x,y)) - ℵ₀ -end - -getindex(::AbstractInfUnitRange, ::Infinity) = ℵ₀ -getindex(::OneToInf, ::Infinity) = ℵ₀ -getindex(v::InfUnitRange, i::Infinity) = ℵ₀ -getindex(v::InfStepRange, i::Infinity) = ℵ₀ function getindex(r::AbstractInfUnitRange, s::AbstractInfUnitRange{<:Integer}) f = first(r) diff --git a/test/runtests.jl b/test/runtests.jl index 7e52145..09a4937 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -404,8 +404,8 @@ end @testset "end" begin @test oneto(∞)[end] ≡ oneto(∞)[∞] ≡ ℵ₀ @test (1:∞)[end] ≡ (1:∞)[∞] ≡ ℵ₀ - @test (1:2:∞)[end] ≡ (1:2:∞)[∞] ≡ ℵ₀ - @test (1.0:2:∞)[end] ≡ (1.0:2:∞)[∞] ≡ ℵ₀ + @test (1:2:∞)[end] ≡ (1:2:∞)[∞] ≡ RealInfinity() + @test (1.0:2:∞)[end] ≡ (1.0:2:∞)[∞] ≡ RealInfinity() end @testset "union" begin From 5d92621a1b24baaf992010c5bb5f60f86bb75f23 Mon Sep 17 00:00:00 2001 From: Tianyi Pu <912396513@qq.com> Date: Fri, 17 Mar 2023 08:56:49 +0000 Subject: [PATCH 2/2] =?UTF-8?q?test=20for=20-=E2=88=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/runtests.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/runtests.jl b/test/runtests.jl index 09a4937..f39fbee 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -406,6 +406,7 @@ end @test (1:∞)[end] ≡ (1:∞)[∞] ≡ ℵ₀ @test (1:2:∞)[end] ≡ (1:2:∞)[∞] ≡ RealInfinity() @test (1.0:2:∞)[end] ≡ (1.0:2:∞)[∞] ≡ RealInfinity() + @test (-1.0:-2:-∞)[end] ≡ (-1.0:-2:-∞)[∞] ≡ -∞ end @testset "union" begin