forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes for non-Int based lengths (JuliaLang#37741)
- Loading branch information
1 parent
4b14f3f
commit 1333a3b
Showing
8 changed files
with
97 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
# InfiniteArrays (arrays with infinite size) | ||
|
||
# This test file is designed to exercise support for generic sizing, | ||
# even though infinite arrays aren't implemented in Base. | ||
|
||
module InfiniteArrays | ||
|
||
export OneToInf, Infinity | ||
|
||
""" | ||
Infinity() | ||
represents infinite cardinality. Note that `Infinity <: Integer` to support | ||
being treated as an index. | ||
""" | ||
struct Infinity <: Integer end | ||
|
||
Base.:(==)(::Infinity, ::Int) = false | ||
Base.:(==)(::Int, ::Infinity) = false | ||
Base.:(<)(::Int, ::Infinity) = true | ||
Base.:(≤)(::Int, ::Infinity) = true | ||
Base.:(≤)(::Infinity, ::Int) = false | ||
Base.:(≤)(::Infinity, ::Infinity) = true | ||
Base.:(-)(::Infinity, ::Int) = Infinity() | ||
Base.:(+)(::Infinity, ::Int) = Infinity() | ||
Base.:(:)(::Infinity, ::Infinity) = 1:0 | ||
|
||
""" | ||
OneToInf(n) | ||
Define an `AbstractInfUnitRange` that behaves like `1:∞`, with the added | ||
distinction that the limits are guaranteed (by the type system) to | ||
be 1 and ∞. | ||
""" | ||
struct OneToInf{T<:Integer} <: AbstractUnitRange{T} end | ||
|
||
OneToInf() = OneToInf{Int}() | ||
|
||
Base.axes(r::OneToInf) = (r,) | ||
Base.unsafe_indices(r::OneToInf) = (r,) | ||
Base.unsafe_length(r::OneToInf) = Infinity() | ||
Base.size(r::OneToInf) = (Infinity(),) | ||
Base.first(r::OneToInf{T}) where {T} = oneunit(T) | ||
Base.length(r::OneToInf{T}) where {T} = Infinity() | ||
Base.last(r::OneToInf{T}) where {T} = Infinity() | ||
Base.unitrange(r::OneToInf) = r | ||
Base.oneto(::Infinity) = OneToInf() | ||
|
||
end |