Skip to content

Commit

Permalink
Fix indexing BigInt axes with large indices (#142)
Browse files Browse the repository at this point in the history
* Fix indexing BigInt axes

* Reinstate inbounds
  • Loading branch information
jishnub authored Sep 6, 2023
1 parent dc43d7c commit 9360eb6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 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.13.1"
version = "0.13.2"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
6 changes: 3 additions & 3 deletions src/InfiniteArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ axistype(::OneToInf{V}, ::OneTo{T}) where {T,V} = OneToInf{promote_type(T,V)}()
# returns the range of indices of v equal to x
# if v does not contain x, returns a 0-length range
# indicating the insertion point of x
function searchsorted(v::AbstractVector, x, ilo::Int, ::PosInfinity, o::Ordering)
function searchsorted(v::AbstractVector, x, ilo::Integer, ::PosInfinity, o::Ordering)
lo = ilo-1
hi = ℵ₀
@inbounds while lo < hi-1
Expand All @@ -182,7 +182,7 @@ end

# index of the first value of vector a that is greater than or equal to x;
# returns length(v)+1 if x is greater than all values in v.
function searchsortedfirst(v::AbstractVector, x, lo::Int, hi::PosInfinity, o::Ordering)
function searchsortedfirst(v::AbstractVector, x, lo::Integer, hi::PosInfinity, o::Ordering)
u = 1
lo = lo - u
hi = ℵ₀
Expand All @@ -199,7 +199,7 @@ end

# index of the last value of vector a that is less than or equal to x;
# returns 0 if x is less than all values of v.
function searchsortedlast(v::AbstractVector, x, lo::Int, hi::PosInfinity, o::Ordering)
function searchsortedlast(v::AbstractVector, x, lo::Integer, hi::PosInfinity, o::Ordering)
u = 1
lo = lo - u
hi = ℵ₀
Expand Down
1 change: 1 addition & 0 deletions src/infrange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ AbstractVector{T}(a::OneToInf) where T<:Real = InfUnitRange{T}(a)
## interface implementations

size(r::InfRanges) = (ℵ₀,)
axes(r::InfRanges{<:Integer}) = (OneToInf{promote_type(Int,eltype(r))}(),)
axes(r::InfRanges) = (OneToInf(),)

isempty(r::InfRanges) = false
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ end
@test ∞:1 1:0

@testset "indexing" begin
@testset "axes" begin
r = axes(big(1):∞,1)
@test r == axes(r,1)
@test r[typemax(Int)+big(1)] == typemax(Int)+big(1)
end
L32 = @inferred(Int32(1):∞)
L64 = @inferred(Int64(1):∞)
@test @inferred(L32[1]) === Int32(1) && @inferred(L64[1]) === Int64(1)
Expand Down

0 comments on commit 9360eb6

Please sign in to comment.