diff --git a/Project.toml b/Project.toml index da6648c..b0c22fb 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "InfiniteArrays" uuid = "4858937d-0d70-526a-a4dd-2d5cb5dd786c" -version = "0.13.7" +version = "0.13.8" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" @@ -11,18 +11,10 @@ LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" -[weakdeps] -DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2" -Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" - -[extensions] -InfiniteArraysDSPExt = "DSP" -InfiniteArraysStatisticsExt = "Statistics" - [compat] Aqua = "0.8" -ArrayLayouts = "1.0" -BandedMatrices = "0.17.18, 1" +ArrayLayouts = "1.8" +BandedMatrices = "0.17.18, 1.0" Base64 = "1" DSP = "0.7" FillArrays = "1.0" @@ -35,6 +27,10 @@ Statistics = "1" Test = "1" julia = "1.6" +[extensions] +InfiniteArraysDSPExt = "DSP" +InfiniteArraysStatisticsExt = "Statistics" + [extras] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" BandedMatrices = "aae01518-5342-5314-be14-df237901396f" @@ -47,3 +43,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] test = ["Aqua", "Test", "BandedMatrices", "LazyBandedMatrices", "Statistics", "SparseArrays", "Base64", "DSP"] + +[weakdeps] +DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" diff --git a/src/infrange.jl b/src/infrange.jl index 7a7288a..4edd6eb 100644 --- a/src/infrange.jl +++ b/src/infrange.jl @@ -513,7 +513,10 @@ cumsum(r::InfRanges) = RangeCumsum(r) diff(r::InfRanges) = Fill(step(r),∞) diff(r::AbstractInfUnitRange{T}) where T = Ones{T}(∞) Base.@propagate_inbounds getindex(c::RangeCumsum, kr::OneToInf) = RangeCumsum(c.range[kr]) -getindex(c::RangeCumsum{<:Any,<:OneToInf}, k::Integer) = k * (k+1) ÷ 2 +Base.@propagate_inbounds function getindex(c::RangeCumsum{<:Any,<:OneToInf}, k::Integer) + @boundscheck checkbounds(c, k) + k * (k+1) ÷ 2 +end function union(r1::RangeCumsum{T1, OneToInf{T1}}, r2::RangeCumsum{T2, OneToInf{T2}}) where {T1,T2} T = promote_type(T1, T2) RangeCumsum(OneToInf{T}()) @@ -522,6 +525,12 @@ Base.issorted(r::RangeCumsum{<:Any,<:OneToInf}) = true Base.sort(r::RangeCumsum{<:Any,<:OneToInf}) = r Base.sort!(r::RangeCumsum{<:Any,<:OneToInf}) = r +getindex(c::RangeCumsum{<:Any,<:OneToInf}, ::InfiniteCardinal{0}) = last(c) +Base.@propagate_inbounds function getindex(c::RangeCumsum{<:Any,<:AbstractRange}, k::InfiniteCardinal{0}) + @boundscheck checkbounds(c, k) + last(c) +end +Base._unsafe_getindex(::IndexStyle, A::RangeCumsum, I::InfiniteCardinal{0}) = last(A) # vcat vcat(a::Number, r::InfRanges) = Vcat(a, r) diff --git a/test/runtests.jl b/test/runtests.jl index 2eb85df..ee4adb7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -226,6 +226,7 @@ end rs = cumsum(r) @test sort(rs) === sort!(rs) === rs @test @inferred((rs -> Val(issorted(rs)))(rs)) isa Val{true} + @test rs[end] ≡ ℵ₀ end end @testset "in" begin @@ -945,6 +946,11 @@ end @test exp.(c)[1:20] == exp.(c[1:20]) end + @test cumsum(3:4:∞)[end] ≡ cumsum(3:4:∞)[∞] ≡ cumsum(3:4:∞)[ℵ₀] ≡ RealInfinity() + @test cumsum(2:∞)[end] ≡ cumsum(2:∞)[∞] ≡ cumsum(2:∞)[ℵ₀] ≡ cumsum(oneto(∞))[end] ≡ cumsum(oneto(∞))[∞] ≡ cumsum(oneto(∞))[ℵ₀] ≡ ℵ₀ + + @test_throws BoundsError cumsum(oneto(∞))[-5] + @test cumsum(1:∞)[2:∞][1:5] == cumsum(1:6)[2:end] @testset "union of cumsum" begin