@@ -20,7 +20,10 @@ using Test
2020
2121algo = GreedyColoringAlgorithm ()
2222
23- @testset " Column decompression" begin
23+ @testset " Column coloring & decompression" begin
24+ problem = ColoringProblem (;
25+ structure= :nonsymmetric , partition= :column , decompression= :direct
26+ )
2427 A0 = sparse ([
2528 1 0 2
2629 0 3 4
@@ -32,17 +35,15 @@ algo = GreedyColoringAlgorithm()
3235 5 0
3336 ]
3437 color0 = [1 , 1 , 2 ]
35- result0 = DefaultColoringResult {:nonsymmetric,:column,:direct} (A0, color0)
3638 @test structurally_orthogonal_columns (A0, color0)
3739 @test directly_recoverable_columns (A0, color0)
38- @test compress (A0, result0) == B0
39- @test decompress (B0, result0) == A0
40- for A in matrix_versions (A0)
41- @test decompress! (respectful_similar (A), B0, result0) == A
42- end
40+ test_coloring_decompression (A0, problem, algo; B0, color0)
4341end ;
4442
45- @testset " Row decompression" begin
43+ @testset " Row coloring & decompression" begin
44+ problem = ColoringProblem (;
45+ structure= :nonsymmetric , partition= :row , decompression= :direct
46+ )
4647 A0 = sparse ([
4748 1 0 3
4849 0 2 0
5354 4 5 0
5455 ]
5556 color0 = [1 , 1 , 2 ]
56- result0 = DefaultColoringResult {:nonsymmetric,:row,:direct} (A0, color0)
5757 @test structurally_orthogonal_columns (transpose (A0), color0)
5858 @test directly_recoverable_columns (transpose (A0), color0)
59- @test compress (A0, result0) == B0
60- @test decompress (B0, result0) == A0
61- for A in matrix_versions (A0)
62- @test decompress! (respectful_similar (A), B0, result0) == A
63- end
59+ test_coloring_decompression (A0, problem, algo; B0, color0)
6460end ;
6561
66- @testset " Symmetric decompression" begin
67- @testset " Direct - Fig 4.1 from 'What color is your Jacobian'" begin
62+ @testset " Symmetric coloring & direct decompression" begin
63+ problem = ColoringProblem (;
64+ structure= :symmetric , partition= :column , decompression= :direct
65+ )
66+ @testset " Fig 4.1 from 'What color is your Jacobian'" begin
6867 example = what_fig_41 ()
6968 A0, B0, color0 = example. A, example. B, example. color
70- result0 = DefaultColoringResult {:symmetric,:column,:direct} (A0, color0)
7169 @test symmetrically_orthogonal_columns (A0, color0)
7270 @test directly_recoverable_columns (A0, color0)
73- @test compress (A0, result0) == B0
74- @test decompress (B0, result0) == A0
75- for A in matrix_versions (A0)
76- @test decompress! (respectful_similar (A), B0, result0) == A
77- end
78- end
79-
80- @testset " Substitution - Fig 6.1 from 'What color is your Jacobian'" begin
81- example = what_fig_61 ()
82- A0, B0, color0 = example. A, example. B, example. color
83- result0 = DefaultColoringResult {:symmetric,:column,:substitution} (A0, color0)
84- result = coloring (
85- A0,
86- ColoringProblem (;
87- structure= :symmetric , partition= :column , decompression= :substitution
88- ),
89- GreedyColoringAlgorithm (),
90- )
91- B = compress (A0, result)
92- @test column_colors (result) != color0
93- @test B != B0
94- @test compress (A0, result0) == B0
95- @test decompress (B, result) ≈ A0
96- @test decompress (B0, result0) ≈ A0
97- for A in matrix_versions (A0)
98- @test decompress! (respectful_similar (A), B0, result0) ≈ A
99- @test decompress! (respectful_similar (A), B, result) ≈ A
100- end
71+ test_coloring_decompression (A0, problem, algo; B0, color0)
10172 end
10273
103- @testset " Direct - Fig 1 from 'Efficient computation of sparse hessians using coloring and AD'" begin
74+ @testset " Fig 1 from 'Efficient computation of sparse hessians using coloring and AD'" begin
10475 example = efficient_fig_1 ()
10576 A0, B0, color0 = example. A, example. B, example. color
106- result0 = DefaultColoringResult {:symmetric,:column,:direct} (A0, color0)
10777 @test symmetrically_orthogonal_columns (A0, color0)
10878 @test directly_recoverable_columns (A0, color0)
109- @test compress (A0, result0) == B0
110- @test decompress (B0, result0) == A0
111- for A in matrix_versions (A0)
112- @test decompress! (respectful_similar (A), B0, result0) == A
113- end
79+ test_coloring_decompression (A0, problem, algo; B0, color0)
80+ end
81+ end ;
82+
83+ @testset " Symmetric coloring & substitution decompression" begin
84+ problem = ColoringProblem (;
85+ structure= :symmetric , partition= :column , decompression= :substitution
86+ )
87+ @testset " Fig 6.1 from 'What color is your Jacobian'" begin
88+ example = what_fig_61 ()
89+ A0, B0, color0 = example. A, example. B, example. color
90+ # our coloring doesn't give the color0 from the example, but that's okay
91+ test_coloring_decompression (A0, problem, algo)
11492 end
11593
116- @testset " Substitution - Fig 4 from 'Efficient computation of sparse hessians using coloring and AD'" begin
94+ @testset " Fig 4 from 'Efficient computation of sparse hessians using coloring and AD'" begin
11795 example = efficient_fig_4 ()
11896 A0, B0, color0 = example. A, example. B, example. color
119- result0 = DefaultColoringResult {:symmetric,:column,:substitution} (A0, color0)
120- result = coloring (
121- A0,
122- ColoringProblem (;
123- structure= :symmetric , partition= :column , decompression= :substitution
124- ),
125- GreedyColoringAlgorithm (),
126- )
127- @test column_colors (result) == color0
128- @test compress (A0, result0) == B0
129- @test compress (A0, result) == B0
130- @test decompress (B0, result0) ≈ A0
131- @test decompress (B0, result) ≈ A0
132- for A in matrix_versions (A0)
133- @test decompress! (respectful_similar (A), B0, result0) ≈ A
134- @test decompress! (respectful_similar (A), B0, result) ≈ A
135- end
97+ test_coloring_decompression (A0, problem, algo; B0, color0)
13698 end
13799end ;
0 commit comments