Added minor
This commit is contained in:
@@ -51,6 +51,13 @@ impl<const H: usize, const W: usize> Matrix<H, W> {
|
||||
self.matrix[0][0] * self.matrix[1][1] - self.matrix[0][1] * self.matrix[1][0]
|
||||
}
|
||||
|
||||
pub fn minor(&self, row: usize, col: usize) -> f32 where
|
||||
[(); H - 1]: ,
|
||||
[(); W - 1]: ,
|
||||
{
|
||||
self.sub_matrix(row, col).determinant()
|
||||
}
|
||||
|
||||
pub fn sub_matrix(&self, skip_row: usize, skip_col: usize) -> Matrix<{H - 1}, {W - 1}>
|
||||
{
|
||||
let mut idx_row: usize = 0;
|
||||
@@ -391,4 +398,18 @@ mod tests {
|
||||
|
||||
assert_eq!(expected, start.sub_matrix(2, 1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn minor_3x3() {
|
||||
let m = Matrix::from_array([
|
||||
[3.0, 5.0, 0.0],
|
||||
[2.0, -1.0, -7.0],
|
||||
[6.0, -1.0, 5.0],
|
||||
]);
|
||||
|
||||
let s = m.sub_matrix(1, 0);
|
||||
|
||||
assert_eq!(25.0, s.determinant());
|
||||
assert_eq!(25.0, m.minor(1, 0));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user