Skip to content

Commit aece171

Browse files
committed
Add AMD tests.
1 parent e92c3a7 commit aece171

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

CSparse.Tests/Ordering/TestAMD.cs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
using CSparse.Ordering;
2+
using CSparse.Storage;
3+
using NUnit.Framework;
4+
5+
namespace CSparse.Tests.Ordering
6+
{
7+
class TestAMD
8+
{
9+
[Test]
10+
public void TestAMD1()
11+
{
12+
int[] ap = [0, 9, 15, 21, 27, 33, 39, 48, 57, 61, 70, 76, 82, 88, 94, 100, 106, 110, 119, 128, 137, 143, 152, 156, 160];
13+
int[] ai = [
14+
/* col 0 */ 0, 5, 6, 12, 13, 17, 18, 19, 21,
15+
/* col 1 */ 1, 8, 9, 13, 14, 17,
16+
/* col 2 */ 2, 6, 11, 20, 21, 22,
17+
/* col 3 */ 3, 7, 10, 15, 18, 19,
18+
/* col 4 */ 4, 7, 9, 14, 15, 16,
19+
/* col 5 */ 0, 5, 6, 12, 13, 17,
20+
/* col 6 */ 0, 2, 5, 6, 11, 12, 19, 21, 23,
21+
/* col 7 */ 3, 4, 7, 9, 14, 15, 16, 17, 18,
22+
/* col 8 */ 1, 8, 9, 14,
23+
/* col 9 */ 1, 4, 7, 8, 9, 13, 14, 17, 18,
24+
/* col 10 */ 3, 10, 18, 19, 20, 21,
25+
/* col 11 */ 2, 6, 11, 12, 21, 23,
26+
/* col 12 */ 0, 5, 6, 11, 12, 23,
27+
/* col 13 */ 0, 1, 5, 9, 13, 17,
28+
/* col 14 */ 1, 4, 7, 8, 9, 14,
29+
/* col 15 */ 3, 4, 7, 15, 16, 18,
30+
/* col 16 */ 4, 7, 15, 16,
31+
/* col 17 */ 0, 1, 5, 7, 9, 13, 17, 18, 19,
32+
/* col 18 */ 0, 3, 7, 9, 10, 15, 17, 18, 19,
33+
/* col 19 */ 0, 3, 6, 10, 17, 18, 19, 20, 21,
34+
/* col 20 */ 2, 10, 19, 20, 21, 22,
35+
/* col 21 */ 0, 2, 6, 10, 11, 19, 20, 21, 22,
36+
/* col 22 */ 2, 20, 21, 22,
37+
/* col 23 */ 6, 11, 12, 23 ];
38+
39+
var S = new SymbolicColumnStorage(24, 24, ap, ai, false);
40+
41+
var p = AMD.Generate(S, ColumnOrdering.MinimumDegreeAtA);
42+
43+
int[] expected = [8, 16, 4, 14, 15, 1, 7, 9, 22, 23, 2, 11, 3, 12, 13, 17, 18, 0, 10, 19, 20, 6, 21, 5, 24];
44+
45+
Assert.That(Permutation.IsValid(p), Is.True);
46+
Assert.That(p, Is.EqualTo(expected).AsCollection);
47+
}
48+
49+
[Test]
50+
public void TestAMD2()
51+
{
52+
int[] ap = [0, 9, 14, 20, 28, 33, 37, 44, 53, 58, 63, 63, 66, 69, 72, 75, 78, 82, 86, 91, 97, 101, 112, 112, 116];
53+
int[] ai = [
54+
/* col 0 */ 0, 17, 18, 21, 5, 12, 5, 0, 13,
55+
/* col 1 */ 14, 1, 8, 13, 17,
56+
/* col 2 */ 2, 20, 11, 6, 11, 22,
57+
/* col 3 */ 3, 3, 10, 7, 18, 18, 15, 19,
58+
/* col 4 */ 7, 9, 15, 14, 16,
59+
/* col 5 */ 5, 13, 6, 17,
60+
/* col 6 */ 5, 0, 11, 6, 12, 6, 23,
61+
/* col 7 */ 3, 4, 9, 7, 14, 16, 15, 17, 18,
62+
/* col 8 */ 1, 9, 14, 14, 14,
63+
/* col 9 */ 7, 13, 8, 1, 17,
64+
/* col 10 */
65+
/* col 11 */ 2, 12, 23,
66+
/* col 12 */ 5, 11, 12,
67+
/* col 13 */ 0, 13, 17,
68+
/* col 14 */ 1, 9, 14,
69+
/* col 15 */ 3, 15, 16,
70+
/* col 16 */ 16, 4, 4, 15,
71+
/* col 17 */ 13, 17, 19, 17,
72+
/* col 18 */ 15, 17, 19, 9, 10,
73+
/* col 19 */ 17, 19, 20, 0, 6, 10,
74+
/* col 20 */ 22, 10, 20, 21,
75+
/* col 21 */ 6, 2, 10, 19, 20, 11, 21, 22, 22, 22, 22,
76+
/* col 22 */
77+
/* col 23 */ 12, 11, 12, 23 ];
78+
79+
var S = new SymbolicColumnStorage(24, 24, ap, ai, false);
80+
81+
var p = AMD.Generate(S, ColumnOrdering.MinimumDegreeAtA);
82+
83+
int[] expected = [10, 11, 23, 12, 2, 6, 8, 14, 15, 16, 4, 1, 9, 7, 18, 3, 5, 17, 0, 19, 20, 21, 13, 22, 24];
84+
85+
Assert.That(Permutation.IsValid(p), Is.True);
86+
Assert.That(p, Is.EqualTo(expected).AsCollection);
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)