MCPcopy Create free account
hub / github.com/Axect/Peroxide / check_matrix

Function check_matrix

examples/clippy_verify.rs:169–205  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

167}
168
169fn check_matrix() {
170 // py_matrix (api.rs:54-55)
171 let m = py_matrix(vec![
172 vec![1.0_f64, 2.0, 3.0, 4.0],
173 vec![5.0, 6.0, 7.0, 8.0],
174 vec![9.0, 10.0, 11.0, 12.0],
175 ]);
176 print_kv("py_matrix 3x4 hash", hash_matrix(&m));
177 // change_shape (matrix.rs:897, 905)
178 let m_col = m.change_shape();
179 print_kv("change_shape Row->Col hash", hash_matrix(&m_col));
180 let m_back = m_col.change_shape();
181 print_kv("change_shape Col->Row hash", hash_matrix(&m_back));
182 // diag (matrix.rs:1105)
183 let sq = ml_matrix("1 2 3; 4 5 6; 7 8 9");
184 let d = sq.diag();
185 print_kv("diag 3x3", hash_f64s(&d));
186 // to_vec (matrix.rs:1184)
187 let v_of_v = sq.to_vec();
188 let flat: Vec<f64> = v_of_v.into_iter().flatten().collect();
189 print_kv("to_vec hash", hash_f64s(&flat));
190 // col_reduce / row_reduce (matrix.rs:2863, 2874)
191 let cr = sq.col_reduce(|c| c.iter().sum::<f64>());
192 let rr = sq.row_reduce(|c| c.iter().sum::<f64>());
193 print_kv("col_reduce sum", hash_f64s(&cr));
194 print_kv("row_reduce sum", hash_f64s(&rr));
195 // is_symmetric (matrix.rs:3660, 3683)
196 let sym = ml_matrix("1 2 3; 2 5 6; 3 6 9");
197 let nonsym = ml_matrix("1 2 3; 4 5 6; 7 8 9");
198 print_kv("is_symmetric sym", sym.is_symmetric());
199 print_kv("is_symmetric nonsym", nonsym.is_symmetric());
200 // matrix.rs:764-765 - inspect; this site is inside `py_matrix`
201 // creation path already exercised above. Cover additionally with a
202 // non-square shape so both row/col loops fire.
203 let rect = py_matrix(vec![vec![1.0_f64, 2.0], vec![3.0, 4.0], vec![5.0, 6.0]]);
204 print_kv("py_matrix 3x2 hash", hash_matrix(&rect));
205}
206
207fn check_polynomial() {
208 let p = poly(vec![1.0, -2.0, 0.5, 3.0]); // 1 - 2x + 0.5x^2 + 3x^3

Callers 1

mainFunction · 0.85

Calls 13

py_matrixFunction · 0.85
print_kvFunction · 0.85
hash_matrixFunction · 0.85
ml_matrixFunction · 0.85
hash_f64sFunction · 0.85
into_iterMethod · 0.80
iterMethod · 0.80
change_shapeMethod · 0.45
diagMethod · 0.45
to_vecMethod · 0.45
col_reduceMethod · 0.45
row_reduceMethod · 0.45

Tested by

no test coverage detected