colamd/
debug.rs

1#[cfg(feature = "debug")]
2use crate::col::Col;
3#[cfg(feature = "debug")]
4use crate::internal::*;
5#[cfg(feature = "debug")]
6use crate::row::Row;
7
8// At this point, all empty rows and columns are dead. All live columns
9// are "clean" (containing no dead rows) and simplicial (no supercolumns
10// yet). Rows may contain dead columns, but all live rows contain at
11// least one live column.
12#[cfg(feature = "debug")]
13pub(crate) fn debug_structures(
14    n_row: Int,
15    n_col: Int,
16    rows: &[Row],
17    cols: &[Col],
18    a_i: &[Int],
19    n_col2: Int,
20) {
21    // Check A, Row, and Col.
22
23    for c in 0..n_col as usize {
24        if col_is_alive(cols, c) {
25            let len = cols[c].length as usize;
26            let score = cols[c].shared2.score();
27            debug4!("initial live col {:5} {:5} {:5}\n", c, len, score);
28            assert_debug!(len > 0);
29            assert_debug!(score >= 0);
30            assert_debug!(cols[c].shared1.thickness() == 1);
31            let mut cp = cols[c].start as usize;
32            let cp_end = cp + len;
33            while cp < cp_end {
34                let r = a_i[cp] as usize;
35                cp += 1;
36                assert_debug!(row_is_alive(rows, r));
37            }
38        } else {
39            let i = cols[c].shared2.order();
40            assert_debug!(i >= n_col2 && i < n_col);
41        }
42    }
43
44    for r in 0..n_row as usize {
45        if row_is_alive(rows, r) {
46            let mut i = 0;
47            let len = rows[r].length as usize;
48            let deg = rows[r].shared1.degree();
49            assert_debug!(len > 0);
50            assert_debug!(deg > 0);
51            let mut rp = rows[r].start as usize;
52            let rp_end = rp + len;
53            while rp < rp_end {
54                let c = a_i[rp] as usize;
55                rp += 1;
56                if col_is_alive(cols, c) {
57                    i += 1;
58                }
59            }
60            assert_debug!(i > 0)
61        }
62    }
63}
64
65// Prints the contents of the degree lists. Counts the number of columns
66// in the degree list and compares it to the total it should have. Also
67// checks the row degrees.
68#[cfg(feature = "debug")]
69pub(crate) fn debug_deg_lists(
70    n_row: Int,
71    n_col: Int,
72    rows: &[Row],
73    cols: &[Col],
74    head: &[Int],
75    min_score: Int,
76    should: Int,
77    max_deg: Int,
78) {
79    // Check the degree lists.
80
81    #[cfg(not(feature = "debug1"))]
82    if n_col > 10000 && debugLevel <= 0 {
83        return;
84    }
85    let mut have = 0;
86    let mut d = format!("Degree lists: {}\n", min_score);
87    for deg in 0..=n_col as usize {
88        let mut col = head[deg];
89        if col == EMPTY {
90            continue;
91        }
92        d.push_str(&format!("{}:", deg));
93        while col != EMPTY {
94            d.push_str(&format!(" {}", col));
95            have += cols[col as usize].shared1.thickness();
96            assert_debug!(col_is_alive(cols, col as usize));
97            col = cols[col as usize].shared4.degree_next();
98        }
99        debug4!("{}", d);
100    }
101    debug4!("should {} have {}", should, have);
102    assert_debug!(should == have);
103
104    // Check the row degrees.
105
106    #[cfg(not(feature = "debug1"))]
107    if n_row > 10000 && debugLevel <= 0 {
108        return;
109    }
110    for row in 0..n_row as usize {
111        if row_is_alive(rows, row) {
112            assert_debug!(rows[row].shared1.degree() <= max_deg);
113        }
114    }
115}
116
117// Ensures that the tag_mark is less that the maximum and also ensures that
118// each entry in the mark array is less than the tag mark.
119#[cfg(feature = "debug")]
120pub(crate) fn debug_mark(n_row: Int, rows: &[Row], tag_mark: Int, max_mark: Int) {
121    // Check the Row marks.
122    assert_debug!(tag_mark > 0 && tag_mark <= max_mark);
123    #[cfg(not(feature = "debug1"))]
124    if n_row > 10000 && debugLevel <= 0 {
125        return;
126    }
127    for r in 0..n_row as usize {
128        assert_debug!(rows[r].shared2.mark() < tag_mark)
129    }
130}
131
132// Prints out the contents of the columns and the rows.
133#[cfg(feature = "debug3")]
134pub(crate) fn debug_matrix(n_row: Int, n_col: Int, rows: &[Row], cols: &[Col], a_i: &[Int]) {
135    // Dump the rows and columns of the matrix.
136    debug3!("DUMP MATRIX:");
137    for r in 0..n_row as usize {
138        debug3!("Row {} alive? {}", r, row_is_alive(rows, r));
139        if row_is_dead(rows, r) {
140            continue;
141        }
142        debug3!(
143            "start {} length {} degree {}",
144            rows[r].start,
145            rows[r].length,
146            rows[r].shared1.degree()
147        );
148        let mut rp = rows[r].start as usize;
149        let rp_end = rp + rows[r].length as usize;
150        while rp < rp_end {
151            let c = a_i[rp] as usize;
152            rp += 1;
153            debug4!("	{} col {}\n", col_is_alive(cols, c), c);
154            //if colIsAlive(cols, c) {
155            //	debug4!("  1 col {}", c);
156            //} else {
157            //	debug4!("  0 col {}", c);
158            //}
159        }
160    }
161
162    for c in 0..n_col as usize {
163        if col_is_alive(cols, c) {
164            debug3!("Col {} alive? 1", c);
165        } else {
166            debug3!("Col {} alive? 0", c);
167        }
168        if col_is_dead(cols, c) {
169            continue;
170        }
171        debug3!(
172            "start {} length {} shared1 {} shared2 {}",
173            cols[c].start,
174            cols[c].length,
175            cols[c].shared1.thickness(),
176            cols[c].shared2.score()
177        );
178        let mut cp = cols[c].start as usize;
179        let cp_end = cp + cols[c].length as usize;
180        while cp < cp_end {
181            let r = a_i[cp] as usize;
182            cp += 1;
183            if row_is_alive(rows, r) {
184                debug4!("  1 row {}", r);
185            } else {
186                debug4!("  0 row {}", r);
187            }
188        }
189    }
190}