Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/InfiniteArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import ArrayLayouts: AbstractBandedLayout, LayoutMatrix, LayoutVecOrMat, LayoutV

import Base.Broadcast: BroadcastStyle, Broadcasted, DefaultArrayStyle, axistype, broadcasted

import FillArrays: AbstractFill, Eye, Fill, Ones, RectDiagonal, Zeros, fill_reshape, getindex_value
import FillArrays: AbstractFill, getindex_value, fill_reshape, RectDiagonal, Fill, Ones, Zeros, Eye, elconvert

import Infinities: InfiniteCardinal, Infinity, ∞

Expand Down
13 changes: 8 additions & 5 deletions src/infrange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,19 @@ struct InfUnitRange{T<:Real} <: AbstractInfUnitRange{T}
start::T
end


InfUnitRange(a::InfUnitRange) = a
InfUnitRange{T}(a::AbstractInfUnitRange) where T<:Real = InfUnitRange{T}(first(a))
InfUnitRange(a::AbstractInfUnitRange{T}) where T<:Real = InfUnitRange{T}(first(a))
unitrange(a::AbstractInfUnitRange) = InfUnitRange(a)

AbstractArray{T}(a::InfUnitRange) where T<:Real = InfUnitRange{T}(a.start)
AbstractVector{T}(a::InfUnitRange) where T<:Real = InfUnitRange{T}(a.start)
for TYPE in (:AbstractArray, :AbstractVector)
@eval $TYPE{T}(a::InfUnitRange) where T<:Integer = InfUnitRange{T}(a.start)
@eval $TYPE{T}(a::InfUnitRange) where T = InfStepRange(T(a.start), one(T))
end
AbstractArray{T}(a::InfStepRange) where T<:Real = InfStepRange(convert(T,a.start), convert(T,a.step))
AbstractVector{T}(a::InfStepRange) where T<:Real = InfStepRange(convert(T,a.start), convert(T,a.step))
elconvert(::Type{T}, r::AbstractInfUnitRange) where T = AbstractArray{T}(r)
elconvert(::Type{T}, r::InfStepRange) where T = AbstractArray{T}(r)

const InfRanges{T} = Union{InfStepRange{T},AbstractInfUnitRange{T}}
const InfAxes = Union{InfRanges{<:Integer},Slice{<:AbstractInfUnitRange{<:Integer}},IdentityUnitRange{<:AbstractInfUnitRange{<:Integer}}}
Expand Down Expand Up @@ -139,8 +142,8 @@ end

AbstractArray{T}(a::OneToInf) where T<:Integer = OneToInf{T}()
AbstractVector{T}(a::OneToInf) where T<:Integer = OneToInf{T}()
AbstractArray{T}(a::OneToInf) where T<:Real = InfUnitRange{T}(a)
AbstractVector{T}(a::OneToInf) where T<:Real = InfUnitRange{T}(a)
AbstractArray{T}(a::OneToInf) where T<:Real = InfStepRange(one(T),one(T))
AbstractVector{T}(a::OneToInf) where T<:Real = InfStepRange(one(T),one(T))


## interface implementations
Expand Down
16 changes: 13 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,12 @@ end
@test sum([1; zeros(∞)]) ≡ 1.0
@test sum([1; ones(∞)]) ≡ 1.0∞
end

@testset "fill algebra" begin
@test Zeros(∞) + (1:∞) ≡ 1.0:∞
@test Ones(∞) + (1:∞) ≡ 2.0:∞
@test Zeros(∞) - (1:∞) ≡ -1.0:-1.0:-∞
end
end

@testset "diagonal" begin
Expand Down Expand Up @@ -1124,19 +1130,23 @@ end
@test convert(AbstractArray{Float64}, 1:∞) ≡ convert(AbstractArray{Float64}, oneto(∞)) ≡
convert(AbstractVector{Float64}, 1:∞) ≡ convert(AbstractVector{Float64}, oneto(∞)) ≡
AbstractVector{Float64}(1:∞) ≡ AbstractVector{Float64}(oneto(∞)) ≡
AbstractArray{Float64}(1:∞) ≡ AbstractArray{Float64}(oneto(∞)) ≡ InfUnitRange(1.0)
AbstractArray{Float64}(1:∞) ≡ AbstractArray{Float64}(oneto(∞)) ≡
float(1:∞) ≡ float(oneto(∞)) ≡
1.0:∞

@test convert(AbstractArray{Float64}, (1:∞)') ≡ convert(AbstractArray{Float64}, oneto(∞)') ≡
convert(AbstractMatrix{Float64}, (1:∞)') ≡ convert(AbstractMatrix{Float64}, oneto(∞)') ≡
AbstractMatrix{Float64}((1:∞)') ≡ AbstractMatrix{Float64}(oneto(∞)') ≡
AbstractArray{Float64}((1:∞)') ≡ AbstractArray{Float64}(oneto(∞)') ≡
InfUnitRange(1.0)'
float((1:∞)') ≡ float(oneto(∞)') ≡
(1.0:∞)'

@test convert(AbstractArray{Float64}, transpose(1:∞)) ≡ convert(AbstractArray{Float64}, transpose(oneto(∞))) ≡
convert(AbstractMatrix{Float64}, transpose(1:∞)) ≡ convert(AbstractMatrix{Float64}, transpose(oneto(∞))) ≡
AbstractMatrix{Float64}(transpose(1:∞)) ≡ AbstractMatrix{Float64}(transpose(oneto(∞))) ≡
AbstractArray{Float64}(transpose(1:∞)) ≡ AbstractArray{Float64}(transpose(oneto(∞))) ≡
transpose(InfUnitRange(1.0))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't this work anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced InfUnitRange(1.0) with 1.0:∞ which is InfStepRange

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

julia> typeof(float(1:5))
StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah should InfUnitRange be restricted to integers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a subtype of OrdinalRange which by definition only accepts integers.

StepRange throws error for float input while UnitRange doesn't... I'm not sure

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a subtype of OrdinalRange which by definition only accepts integers.

I don't think there's a strict requirement on element types, only that the step should be an integer. Floating point UnitRanges are currently allowed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Floating point UnitRanges are currently allowed

They are, but the only way to construct them is the default constructor. The tests convert eltypes, which always result in StepRangeLen in Julia Base.

float(transpose(1:∞)) ≡ float(transpose(oneto(∞))) ≡
transpose(1.0:∞)
end

@testset "cached indexing" begin
Expand Down
Loading