Skip to content

Commit 1be18d4

Browse files
committed
add tests
1 parent 04c8993 commit 1be18d4

File tree

5 files changed

+187
-14
lines changed

5 files changed

+187
-14
lines changed

ext/InfiniteArraysBlockArraysExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import ArrayLayouts: sub_materialize, axes_print_matrix_row
88
import InfiniteArrays: OneToInf, PosInfinity, InfRanges, RealInfinity, Infinity, InfStepRange, TridiagonalToeplitzLayout
99
import BlockArrays: AbstractBlockLayout, sizes_from_blocks, BlockTridiagonal, OneToCumsum, BlockSlice, AbstractBlockedUnitRange,
1010
BlockLayout
11-
import LazyArrays: PaddedColumns
11+
import LazyArrays: PaddedColumns, LazyArrayStyle
1212

1313
const OneToInfCumsum = RangeCumsum{Int,OneToInf{Int}}
1414

test/runtests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,8 +1245,6 @@ end
12451245
@test r[ind] == v
12461246
end
12471247

1248-
include("test_infconv.jl")
1249-
include("test_block.jl")
12501248

12511249
@testset "bounds-checking for StepRangeLen{<:CartesianIndex}" begin
12521250
if VERSION >= v"1.11.0-rc3"
@@ -1259,9 +1257,11 @@ end
12591257
a = [1+im,2+im]
12601258
A = a * Ones{Complex{Int}}(1,∞)
12611259
@test A[:,1:5] == a * ones(1,5)
1262-
1260+
12631261
@test (a*permutedims(1:∞))[:,1:5] == a*(1:5)'
12641262
@test (a*Hcat(Zeros(1,2), permutedims(1:∞)))[1,1:5] == (a*Vcat(Hcat(Zeros(1,2), permutedims(1:∞))))[1,1:5]
12651263
end
12661264

1265+
include("test_infconv.jl")
1266+
include("test_infblock.jl")
12671267
include("test_infbanded.jl")

test/test_block.jl

Lines changed: 0 additions & 10 deletions
This file was deleted.

test/test_infblock.jl

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
using InfiniteArrays, BlockArrays, LazyArrays, Test
2+
using InfiniteArrays: OneToInf, RealInfinity
3+
using Base: oneto
4+
using LazyArrays: LazyArrayStyle
5+
using BlockArrays: BlockTridiagonal
6+
7+
const InfiniteArraysBlockArraysExt = Base.get_extension(InfiniteArrays, :InfiniteArraysBlockArraysExt)
8+
9+
10+
11+
12+
@testset "∞-block arrays" begin
13+
@testset "blockedonetoinf" begin
14+
b = blockedrange(OneToInf())
15+
b2 = b .+ b;
16+
for i in 1:10
17+
@test b2[Block(i)] == b[Block(i)] + b[Block(i)]
18+
end
19+
end
20+
21+
@testset "fixed block size" begin
22+
k = Base.OneTo.(oneto(∞))
23+
n = Fill.(oneto(∞), oneto(∞))
24+
@test broadcast(length, k) map(length, k) OneToInf()
25+
@test broadcast(length, n) map(length, n) OneToInf()
26+
27+
b = mortar(Fill([1, 2], ∞))
28+
@test blockaxes(b, 1) Block.(OneToInf())
29+
@test b[Block(5)] == [1, 2]
30+
@test b[Block.(2:∞)][Block.(2:10)] == b[Block.(3:11)]
31+
@test exp.(b)[Block.(2:∞)][Block.(2:10)] == exp.(b[Block.(3:11)])
32+
33+
@test blockedrange(Vcat(2, Fill(3, ∞))) isa BlockedOneTo{<:Any,<:InfiniteArrays.InfStepRange}
34+
35+
c = BlockedArray(1:∞, Vcat(2, Fill(3, ∞)))
36+
@test c[Block.(2:∞)][Block.(2:10)] == c[Block.(3:11)]
37+
38+
@test length(axes(b, 1)) ℵ₀
39+
@test last(axes(b, 1)) ℵ₀
40+
@test Base.BroadcastStyle(typeof(b)) isa LazyArrayStyle{1}
41+
end
42+
43+
@testset "1:∞ blocks" begin
44+
a = blockedrange(oneto(∞))
45+
@test axes(a, 1) == a
46+
o = Ones((a,))
47+
@test Base.BroadcastStyle(typeof(a)) isa LazyArrayStyle{1}
48+
b = exp.(a)
49+
@test axes(b, 1) == a
50+
@test o .* b isa typeof(b)
51+
@test b .* o isa typeof(b)
52+
end
53+
54+
@testset "padded" begin
55+
c = BlockedArray([1; zeros(∞)], Vcat(2, Fill(3, ∞)))
56+
@test c + c isa BlockedVector
57+
end
58+
59+
60+
@testset "triangle recurrences" begin
61+
@testset "n and k" begin
62+
n = mortar(Fill.(oneto(∞), oneto(∞)))
63+
k = mortar(Base.OneTo.(oneto(∞)))
64+
65+
@test n[Block(5)] layout_getindex(n, Block(5)) view(n, Block(5)) Fill(5, 5)
66+
@test k[Block(5)] layout_getindex(k, Block(5)) view(k, Block(5)) Base.OneTo(5)
67+
@test Base.BroadcastStyle(typeof(n)) isa LazyArrays.LazyArrayStyle{1}
68+
@test Base.BroadcastStyle(typeof(k)) isa LazyArrays.LazyArrayStyle{1}
69+
70+
N = 1000
71+
v = view(n, Block.(Base.OneTo(N)))
72+
@test view(v, Block(2)) Fill(2, 2)
73+
@test axes(v) isa Tuple{BlockedOneTo{Int,ArrayLayouts.RangeCumsum{Int64,Base.OneTo{Int64}}}}
74+
@test @allocated(axes(v)) 40
75+
76+
dest = BlockedArray{Float64}(undef, axes(v))
77+
@test copyto!(dest, v) == v
78+
@test @allocated(copyto!(dest, v)) 40
79+
80+
v = view(k, Block.(Base.OneTo(N)))
81+
@test view(v, Block(2)) Base.OneTo(2)
82+
@test axes(v) isa Tuple{BlockedOneTo{Int,ArrayLayouts.RangeCumsum{Int64,Base.OneTo{Int64}}}}
83+
@test @allocated(axes(v)) 40
84+
@test copyto!(dest, v) == v
85+
86+
@testset "stack overflow" begin
87+
i = Base.to_indices(k, (Block.(2:∞),))[1].indices
88+
@test last(i) == ℵ₀
89+
end
90+
91+
v = view(k, Block.(2:∞))
92+
@test Base.BroadcastStyle(typeof(v)) isa LazyArrayStyle{1}
93+
@test v[Block(1)] == 1:2
94+
@test v[Block(1)] k[Block(2)] Base.OneTo(2)
95+
96+
@test axes(n, 1) isa BlockedOneTo{Int,ArrayLayouts.RangeCumsum{Int64,OneToInf{Int64}}}
97+
end
98+
end
99+
100+
@testset "blockdiag" begin
101+
D = Diagonal(mortar(Fill.((-(0:∞) - (0:∞) .^ 2), 1:2:∞)))
102+
x = [randn(5); zeros(∞)]
103+
= BlockedArray(x, (axes(D, 1),))
104+
@test (D*x)[1:10] == (D*x̃)[1:10]
105+
end
106+
107+
@testset "sortedunion" begin
108+
a = cumsum(1:2:∞)
109+
@test BlockArrays.sortedunion(a, a) a
110+
@test BlockArrays.sortedunion([∞], a) BlockArrays.sortedunion(a, [∞]) a
111+
@test BlockArrays.sortedunion([∞], [∞]) == [∞]
112+
113+
b = Vcat([1, 2], 3:∞)
114+
c = Vcat(1, 3:∞)
115+
@test BlockArrays.sortedunion(b, b) b
116+
@test BlockArrays.sortedunion(c, c) c
117+
end
118+
119+
@testset "Algebra" begin
120+
@testset "Triangle OP recurrences" begin
121+
k = mortar(Base.OneTo.(1:∞))
122+
n = mortar(Fill.(1:∞, 1:∞))
123+
@test k[Block.(2:3)] isa BlockArray
124+
@test n[Block.(2:3)] isa BlockArray
125+
@test k[Block.(2:3)] == [1, 2, 1, 2, 3]
126+
@test n[Block.(2:3)] == [2, 2, 3, 3, 3]
127+
@test blocksize(BroadcastVector(exp, k)) == (ℵ₀,)
128+
@test BroadcastVector(exp, k)[Block.(2:3)] == exp.([1, 2, 1, 2, 3])
129+
# BroadcastVector(+,k,n)
130+
end
131+
# Multivariate OPs Corollary (3)
132+
# n = 5
133+
# BlockTridiagonal(Zeros.(1:∞,2:∞),
134+
# (n -> Diagonal(((n+2).+(0:n)))/ (2n + 2)).(0:∞),
135+
# Zeros.(2:∞,1:∞))
136+
end
137+
138+
@testset "findblock at +∞, HarmonicOrthogonalPolynomials#88" begin
139+
@test findblock(blockedrange(1:2:∞), RealInfinity()) == Block(ℵ₀)
140+
end
141+
end

test/test_infblockbanded.jl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const BlockTriPertToeplitz = InfiniteArraysBlockArraysExt.BlockTriPertToeplitz
2+
3+
@testset "BlockBanded" begin
4+
a = b = c = 0.0
5+
n = mortar(Fill.(oneto(∞), oneto(∞)))
6+
k = mortar(Base.OneTo.(oneto(∞)))
7+
Dy = BlockBandedMatrices._BandedBlockBandedMatrix((k .+ (b + c))', axes(k, 1), (-1, 1), (-1, 1))
8+
N = 100
9+
@test Dy[Block.(1:N), Block.(1:N)] == BlockBandedMatrices._BandedBlockBandedMatrix((k.+(b+c))[Block.(1:N)]', axes(k, 1)[Block.(1:N)], (-1, 1), (-1, 1))
10+
@test colsupport(Dy, axes(Dy,2)) == 1:
11+
@test rowsupport(Dy, axes(Dy,1)) == 2:
12+
end
13+
14+
15+
16+
@testset "BlockTridiagonal" begin
17+
A = BlockTridiagonal(Vcat([fill(1.0, 2, 1), Matrix(1.0I, 2, 2), Matrix(1.0I, 2, 2), Matrix(1.0I, 2, 2)], Fill(Matrix(1.0I, 2, 2), ∞)),
18+
Vcat([zeros(1, 1)], Fill(zeros(2, 2), ∞)),
19+
Vcat([fill(1.0, 1, 2), Matrix(1.0I, 2, 2)], Fill(Matrix(1.0I, 2, 2), ∞)))
20+
21+
@test A isa BlockTriPertToeplitz
22+
@test isblockbanded(A)
23+
24+
@test A[Block.(1:2), Block(1)] == A[1:3, 1:1] == reshape([0.0, 1.0, 1.0], 3, 1)
25+
26+
@test BlockBandedMatrix(A)[1:100, 1:100] == BlockBandedMatrix(A, (2, 1))[1:100, 1:100] == BlockBandedMatrix(A, (1, 1))[1:100, 1:100] == A[1:100, 1:100]
27+
28+
@test (A-I)[1:100, 1:100] == A[1:100, 1:100] - I
29+
@test (A+I)[1:100, 1:100] == A[1:100, 1:100] + I
30+
@test (I+A)[1:100, 1:100] == I + A[1:100, 1:100]
31+
@test (I-A)[1:100, 1:100] == I - A[1:100, 1:100]
32+
33+
@test (A-im*I)[1:100, 1:100] == A[1:100, 1:100] - im * I
34+
@test (A+im*I)[1:100, 1:100] == A[1:100, 1:100] + im * I
35+
@test (im*I+A)[1:100, 1:100] == im * I + A[1:100, 1:100]
36+
@test (im*I-A)[1:100, 1:100] == im * I - A[1:100, 1:100]
37+
38+
T = mortar(LazyBandedMatrices.Tridiagonal(Fill([1 2; 3 4], ∞), Fill([1 2; 3 4], ∞), Fill([1 2; 3 4], ∞)));
39+
#TODO: copy BlockBidiagonal code from BlockBandedMatrices to LazyBandedMatrices
40+
@test T[Block(2, 2)] == [1 2; 3 4]
41+
@test_broken T[Block(1, 3)] == Zeros(2, 2)
42+
end

0 commit comments

Comments
 (0)