Skip to content

Commit cd12c7e

Browse files
authored
Latest FillArrays/LazyArrays (#15)
* FillArrays 0.7, BandedMatrix tests * remove _materialize * update for no VCat * Banded Lazy * similar(::Type, ...) * v0.2
1 parent 43e8fdd commit cd12c7e

File tree

5 files changed

+54
-25
lines changed

5 files changed

+54
-25
lines changed

Project.toml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "InfiniteArrays"
22
uuid = "4858937d-0d70-526a-a4dd-2d5cb5dd786c"
3-
version = "0.1.3"
3+
version = "0.2"
44

55
[deps]
66
DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2"
@@ -9,10 +9,16 @@ LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02"
99
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1010
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1111
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
12-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1312

1413
[compat]
1514
DSP = "0.5.1, 0.6"
16-
FillArrays = "0.6"
17-
LazyArrays = "0.10"
15+
FillArrays = "0.6, 0.7"
16+
LazyArrays = "0.11"
1817
julia = "1"
18+
19+
[extras]
20+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
21+
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
22+
23+
[targets]
24+
test = ["Test", "BandedMatrices"]

src/InfiniteArrays.jl

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ import LinearAlgebra: BlasInt, BlasFloat, norm, diag, diagm, ishermitian, issymm
3434
import Statistics: mean, median
3535

3636
import FillArrays: AbstractFill, getindex_value
37-
import LazyArrays: LazyArrayStyle, _materialize, AbstractBandedLayout,
38-
ZerosLayout, VcatLayout, @lazymul, mulapplystyle, AbstractArrayApplyStyle,
39-
ArrayMuls
37+
import LazyArrays: LazyArrayStyle, AbstractBandedLayout, MemoryLayout, LazyLayout,
38+
ZerosLayout, @lazymul, AbstractArrayApplyStyle
4039

4140
import DSP: conv
4241

@@ -93,16 +92,5 @@ UnitRange{T}(start::Integer, ::Infinity) where T<:Real = InfUnitRange{T}(start)
9392

9493
Int(::Infinity) =
9594

96-
# stay lazy if infinite
97-
_materialize(M::Mul{<:AbstractArrayApplyStyle,<:Tuple{Vararg{<:AbstractArray}}}, ::Tuple{<:OneToInf,<:OneToInf}) = ApplyArray(M)
98-
_materialize(M::Mul{<:AbstractArrayApplyStyle,<:Tuple{Vararg{<:AbstractArray}}}, ::Tuple{<:OneToInf}) = ApplyArray(M)
99-
_materialize(M::Mul{<:AbstractArrayApplyStyle,<:Tuple{Vararg{<:AbstractArray}}}, ::Tuple{<:OneToInf,<:OneTo}) = ApplyArray(M)
100-
_materialize(M::Mul{<:AbstractArrayApplyStyle,<:Tuple{Vararg{<:AbstractArray}}}, ::Tuple{<:OneTo,<:OneToInf}) = ApplyArray(M)
101-
_materialize(M::ArrayMuls, ::Tuple{<:OneToInf,<:OneToInf}) = ApplyArray(M)
102-
_materialize(M::ArrayMuls, ::Tuple{<:OneToInf}) = ApplyArray(M)
103-
_materialize(M::ArrayMuls, ::Tuple{<:OneToInf,<:OneTo}) = ApplyArray(M)
104-
_materialize(M::ArrayMuls, ::Tuple{<:OneTo,<:OneToInf}) = ApplyArray(M)
105-
106-
10795

10896
end # module

src/infarrays.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ similar(A::AbstractArray, ::Type{T}, axes::Tuple{OneToInf{Int},OneToInf{Int}}) w
2424
similar(A::AbstractArray, ::Type{T}, dims::Tuple{Infinity}) where T = cache(Zeros{T}(dims))
2525
similar(A::AbstractArray, ::Type{T}, dims::Tuple{Infinity,Infinity}) where T = cache(Zeros{T}(dims))
2626

27+
similar(::Type{<:AbstractArray{T}}, axes::Tuple{OneToInf{Int}}) where T = cache(Zeros{T}(axes))
28+
similar(::Type{<:AbstractArray{T}}, axes::Tuple{OneToInf{Int},OneToInf{Int}}) where T = cache(Zeros{T}(axes))
29+
similar(::Type{<:AbstractArray{T}}, dims::Tuple{Infinity}) where T = cache(Zeros{T}(dims))
30+
similar(::Type{<:AbstractArray{T}}, dims::Tuple{Infinity,Infinity}) where T = cache(Zeros{T}(dims))
31+
32+
2733
zeros(::Type{T}, ::Tuple{Infinity}) where T = cache(Zeros{T}(∞))
2834
zeros(::Type{T}, nm::Tuple{Integer, Infinity}) where T = cache(Zeros{T}(nm...))
2935
zeros(::Type{T}, nm::Tuple{Infinity, Integer}) where T = cache(Zeros{T}(nm...))
@@ -124,4 +130,4 @@ _gettail(k, a::Number, b...) = k ≤ 1 ? tuple(a, b...) : _gettail(k - length(a
124130
_gettail(k, a, b...) = k  length(a) ? tuple(a[k:end], b...) : _gettail(k - length(a), b...)
125131
_vcat(a) = a
126132
_vcat(a, b, c...) = Vcat(a, b, c...)
127-
_unsafe_getindex(::IndexLinear, A::Vcat, r::InfUnitRange) = _vcat(_gettail(first(r), A.arrays...)...)
133+
_unsafe_getindex(::IndexLinear, A::Vcat, r::InfUnitRange) = _vcat(_gettail(first(r), A.args...)...)

src/infrange.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# This file is mmodified from Julia. License is MIT: https://julialang.org/license
22

33
(:)(start::T, stop::Infinity) where {T<:Integer} = InfUnitRange{T}(start)
4+
(:)(start::Infinity, stop::Integer) = start+1:start
45
function (:)(start::T, step::T, stop::OrientedInfinity) where {T<:Real}
56
sign(step) == sign(stop) || throw(ArgumentError("InfStepRange must have infinite length"))
67
InfStepRange(start, step)
@@ -439,3 +440,11 @@ function conv(r1::Ones{<:Any,1,<:Tuple{<:OneToInf}}, r2::AbstractFill{<:Any,1,<:
439440
a = getindex_value(r1) * getindex_value(r2)
440441
a:a:
441442
end
443+
444+
445+
###
446+
# MemoryLayout
447+
####
448+
449+
MemoryLayout(::Type{<:AbstractInfUnitRange}) = LazyLayout()
450+
MemoryLayout(::Type{<:InfStepRange}) = LazyLayout()

test/runtests.jl

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using LinearAlgebra, SparseArrays, InfiniteArrays, FillArrays, LazyArrays, Statistics, DSP, Test
1+
using LinearAlgebra, SparseArrays, InfiniteArrays, FillArrays, LazyArrays, Statistics, DSP, BandedMatrices, Test
22
import InfiniteArrays: OrientedInfinity, OneToInf, InfUnitRange, InfStepRange
3-
import LazyArrays: CachedArray
4-
3+
import LazyArrays: CachedArray, MemoryLayout, LazyLayout
4+
import BandedMatrices: _BandedMatrix, BandedColumns
55

66
@testset "" begin
77
@test 1
@@ -420,6 +420,8 @@ end
420420
@test D[1:10,1:10] == Diagonal(1:10)
421421
@test_broken D^2 isa Diagonal
422422
@test D*D isa Diagonal
423+
@test MemoryLayout(typeof(D.diag)) == LazyLayout()
424+
@test MemoryLayout(typeof(D)) == LazyLayout()
423425
@test Ones(∞,∞)*D isa ApplyArray
424426
@test (Ones(∞,∞)*D)[1:10,1:10] == Ones(10,10)*D[1:10,1:10]
425427
end
@@ -540,8 +542,8 @@ end
540542
@test diff(x[1:10]) == diff(x)[1:9]
541543
@test diff(y)[1:20] == x[2:21]
542544

543-
@test cumsum(x).arrays[2] 8:12
544-
@test last(y.arrays) == sum(x[1:9]):2:
545+
@test cumsum(x).args[2] 8:12
546+
@test last(y.args) == sum(x[1:9]):2:
545547
r = (3:4:∞)
546548
@test cumsum(r)[1:20] == cumsum(r[1:20])
547549
end
@@ -596,6 +598,24 @@ end
596598
@test size(A*B) == (3,∞)
597599
@test (A*B)[1:3,1:10] == Fill(1,3,10)*Diagonal(1:10)
598600

599-
@test_broken A*B*C isa ApplyArray
601+
@test A*B*C isa ApplyArray
602+
@test size(A*B*C) == (3,)
603+
@test (A*B*C)[1] == 14
604+
@test A*B*C == fill(14,3)
605+
@test_throws BoundsError (A*B*C)[1:10,1:10]
600606
@test A*B*D isa ApplyArray
607+
@test (A*B*D)[1:3,1:5] == fill(6.0,3,5)
608+
end
609+
610+
@testset "MemoryLayout" begin
611+
@test MemoryLayout(OneToInf{Int}) == LazyLayout()
612+
@test MemoryLayout(typeof((0:∞))) == LazyLayout()
613+
@test MemoryLayout(typeof((0:∞)')) == LazyLayout()
614+
A = _BandedMatrix((0:∞)', ∞, -1, 1)
615+
@test MemoryLayout(typeof(A)) == BandedColumns{LazyLayout}()
616+
end
617+
618+
@testset "Banded" begin
619+
A = _BandedMatrix((0:∞)', ∞, -1, 1)
620+
@test_broken apply(*, Eye(∞), A) A
601621
end

0 commit comments

Comments
 (0)