Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

last of InfStepRange should be RealInfinity #120

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/infarrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 4 additions & 21 deletions src/infrange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,9 @@ 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()
@test (-1.0:-2:-∞)[end] ≡ (-1.0:-2:-∞)[∞] ≡ -∞
end

@testset "union" begin
Expand Down