From d9f862f6fbb6a23feb86e54f125883a5a93dd9b2 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 27 Aug 2024 15:32:41 +0530 Subject: [PATCH] Fast bounds-check for infinite CartesianIndex StepRangeLen (#190) * Fast bounds-check for infinite CartesianIndex StepRangeLen * Bump version to v0.14.3 --- Project.toml | 2 +- src/infrange.jl | 7 ++++++- test/runtests.jl | 9 ++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index 9829fb6..14dedd8 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "InfiniteArrays" uuid = "4858937d-0d70-526a-a4dd-2d5cb5dd786c" -version = "0.14.2" +version = "0.14.3" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" diff --git a/src/infrange.jl b/src/infrange.jl index 12d8e94..928e540 100644 --- a/src/infrange.jl +++ b/src/infrange.jl @@ -624,4 +624,9 @@ function inv(D::Diagonal{<:Any, <:InfRanges}) idx = findfirst(iszero, d) isnothing(idx) || throw(SingularException(idx)) return Diagonal(inv.(d)) -end \ No newline at end of file +end + +# bounds-checking +function Base.checkindex(::Type{Bool}, inds::NTuple{N, AbstractInfUnitRange}, i::AbstractRange{CartesianIndex{N}}) where {N} + isempty(i) | checkindex(Bool, inds, first(i)) +end diff --git a/test/runtests.jl b/test/runtests.jl index 6ddbc9f..45277cd 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1230,4 +1230,11 @@ end end include("test_infconv.jl") -include("test_block.jl") \ No newline at end of file +include("test_block.jl") + +@testset "bounds-checking for StepRangeLen{<:CartesianIndex}" begin + if VERSION >= v"1.11.0-rc3" + D = Diagonal(1:∞) + @test checkbounds(Bool, D, diagind(D, IndexCartesian())) + end +end