diff --git a/src/InfiniteArrays.jl b/src/InfiniteArrays.jl index 5854d31..0f2aa93 100644 --- a/src/InfiniteArrays.jl +++ b/src/InfiniteArrays.jl @@ -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, ∞ diff --git a/src/infrange.jl b/src/infrange.jl index 6814d13..d841f3c 100644 --- a/src/infrange.jl +++ b/src/infrange.jl @@ -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}}} @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 3d39749..4c3a962 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 @@ -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)) + float(transpose(1:∞)) ≡ float(transpose(oneto(∞))) ≡ + transpose(1.0:∞) end @testset "cached indexing" begin