Skip to content

Commit

Permalink
Fast bounds-check for infinite CartesianIndex StepRangeLen (#190)
Browse files Browse the repository at this point in the history
* Fast bounds-check for infinite CartesianIndex StepRangeLen

* Bump version to v0.14.3
  • Loading branch information
jishnub authored Aug 27, 2024
1 parent 83860f6 commit d9f862f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
7 changes: 6 additions & 1 deletion src/infrange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -624,4 +624,9 @@ function inv(D::Diagonal{<:Any, <:InfRanges})
idx = findfirst(iszero, d)
isnothing(idx) || throw(SingularException(idx))
return Diagonal(inv.(d))
end
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
9 changes: 8 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1230,4 +1230,11 @@ end
end

include("test_infconv.jl")
include("test_block.jl")
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

0 comments on commit d9f862f

Please # to comment.