1+ using ArrayInterface: ArrayInterface
12using BandedMatrices: BandedMatrix, brand
3+ using BlockBandedMatrices: BlockBandedMatrix
24using LinearAlgebra
35using SparseMatrixColorings
46using SparseMatrixColorings: cycle_range
57using Test
68
7- column_problem = ColoringProblem (; structure= :nonsymmetric , partition= :column )
8- row_problem = ColoringProblem (; structure= :nonsymmetric , partition= :row )
9-
10- algo = GreedyColoringAlgorithm ()
11-
129@testset " Utils" begin
1310 @test cycle_range (2 , 3 ) == [1 , 2 , 1 ]
1411 @test cycle_range (2 , 4 ) == [1 , 2 , 1 , 2 ]
@@ -18,87 +15,43 @@ algo = GreedyColoringAlgorithm()
1815 @test cycle_range (2 , 1 ) == [1 ]
1916 @test cycle_range (3 , 1 ) == [1 ]
2017 @test cycle_range (3 , 2 ) == [1 , 2 ]
21- end
18+ end ;
2219
2320@testset " Diagonal" begin
24- for n in (1 , 2 , 10 , 100 , 1000 )
21+ @testset for n in (1 , 2 , 10 , 100 )
2522 A = Diagonal (rand (n))
26- # column
27- result = coloring (A, column_problem, algo)
28- B = compress (A, result)
29- D = decompress (B, result)
30- @test size (B, 2 ) == 1
31- @test D == A
32- @test D isa Diagonal
33- # row
34- result = coloring (A, row_problem, algo)
35- B = compress (A, result)
36- D = decompress (B, result)
37- @test size (B, 1 ) == 1
38- @test D == A
39- @test D isa Diagonal
23+ test_structured_coloring_decompression (A)
4024 end
41- end
25+ end ;
4226
4327@testset " Bidiagonal" begin
44- for n in (2 , 10 , 100 , 1000 )
28+ @testset for n in (2 , 10 , 100 )
4529 A1 = Bidiagonal (rand (n), rand (n - 1 ), :U )
4630 A2 = Bidiagonal (rand (n), rand (n - 1 ), :L )
47- for A in (A1, A2)
48- # column
49- result = coloring (A, column_problem, algo)
50- B = compress (A, result)
51- D = decompress (B, result)
52- @test size (B, 2 ) == 2
53- @test D == A
54- @test D isa Bidiagonal
55- # row
56- result = coloring (A, row_problem, algo)
57- B = compress (A, result)
58- D = decompress (B, result)
59- @test size (B, 1 ) == 2
60- @test D == A
61- @test D isa Bidiagonal
62- end
31+ test_structured_coloring_decompression (A1)
32+ test_structured_coloring_decompression (A2)
6333 end
64- end
34+ end ;
6535
6636@testset " Tridiagonal" begin
67- for n in (2 , 10 , 100 , 1000 )
68- A1 = Tridiagonal (rand (n - 1 ), rand (n), rand (n - 1 ))
69- A2 = Tridiagonal (rand (n - 1 ), rand (n), rand (n - 1 ))
70- for A in (A1, A2)
71- # column
72- result = coloring (A, column_problem, algo)
73- B = compress (A, result)
74- D = decompress (B, result)
75- @test size (B, 2 ) == min (n, 3 )
76- @test D == A
77- @test D isa Tridiagonal # row
78- result = coloring (A, row_problem, algo)
79- B = compress (A, result)
80- D = decompress (B, result)
81- @test size (B, 1 ) == min (n, 3 )
82- @test D == A
83- @test D isa Tridiagonal
84- end
37+ for n in (2 , 10 , 100 )
38+ A = Tridiagonal (rand (n - 1 ), rand (n), rand (n - 1 ))
39+ test_structured_coloring_decompression (A)
8540 end
86- end
41+ end ;
8742
8843@testset " BandedMatrices" begin
89- for (m, n) in [(10 , 20 ), (20 , 10 )], l in 0 : 5 , u in 0 : 5
44+ @testset for (m, n) in [(10 , 20 ), (20 , 10 )], l in 0 : 5 , u in 0 : 5
9045 A = brand (m, n, l, u)
91- # column
92- result = coloring (A, column_problem, algo)
93- B = compress (A, result)
94- D = decompress (B, result)
95- @test D == A
96- @test D isa BandedMatrix
97- # row
98- result = coloring (A, row_problem, algo)
99- B = compress (A, result)
100- D = decompress (B, result)
101- @test D == A
102- @test D isa BandedMatrix
46+ test_structured_coloring_decompression (A)
47+ end
48+ end ;
49+
50+ @testset " BlockBandedMatrices" begin
51+ @testset for (mb, nb) in [(10 , 20 ), (20 , 10 )], lb in 0 : 3 , ub in 0 : 3 , bs in 1 : 3
52+ rows = rand (1 : bs, mb)
53+ cols = rand (1 : bs, nb)
54+ A = BlockBandedMatrix {Float64} (rand (sum (rows), sum (cols)), rows, cols, (l, u))
55+ test_structured_coloring_decompression (A)
10356 end
104- end
57+ end ;
0 commit comments