Skip to content

Commit fa799fb

Browse files
committed
Start Bi-infinite ranges
1 parent b17e35b commit fa799fb

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

src/InfiniteArrays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ end
211211
return LazyArrays.searchsortedlast_recursive(n, x, args...)
212212
end
213213

214-
214+
include("biinfrange.jl")
215215

216216

217217
end # module

src/biinfrange.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
BiInfUnitRange()
3+
4+
Represent -∞:∞ with offset indexing
5+
"""
6+
struct BiInfUnitRange{T<:Real} <: AbstractInfUnitRange{T} end
7+
8+
BiInfUnitRange() = BiInfUnitRange{Int}()
9+
10+
AbstractArray{T}(a::BiInfUnitRange) where T<:Real = BiInfUnitRange{T}(a)
11+
AbstractVector{T}(a::BiInfUnitRange) where T<:Real = BiInfUnitRange{T}(a)
12+
13+
unitrange(a::BiInfUnitRange) = a
14+
Base.has_offset_axes(::BiInfUnitRange) = true
15+
16+
getindex(v::BiInfUnitRange{T}, i::Integer) where T = convert(T, i)
17+
axes(::BiInfUnitRange) = (BiInfUnitRange(),)
18+
first(::BiInfUnitRange) = -
19+
show(io::IO, ::BiInfUnitRange{Int}) = print(io, "BiInfUnitRange()")
20+
21+
getindex(r::BiInfUnitRange{T}, s::AbstractUnitRange{<:Integer}) where T = convert(AbstractVector{T}, s)

test/test_biinfrange.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using InfiniteArrays, Base64, Test
2+
using InfiniteArrays: BiInfUnitRange
3+
4+
@testset "-∞:∞" begin
5+
r = BiInfUnitRange()
6+
@test stringmime("text/plain", r) == "BiInfUnitRange()"
7+
8+
end

0 commit comments

Comments
 (0)