minor without calling submatrix
This commit is contained in:
@@ -51,11 +51,37 @@ 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]
|
self.matrix[0][0] * self.matrix[1][1] - self.matrix[0][1] * self.matrix[1][0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn zero_skip(&self, val: usize) -> usize {
|
||||||
|
if val == 0 {
|
||||||
|
1
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bound_skip(&self, val: usize, bound: usize) -> usize {
|
||||||
|
if val < bound {
|
||||||
|
bound
|
||||||
|
} else {
|
||||||
|
bound - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn minor(&self, row: usize, col: usize) -> f32 where
|
pub fn minor(&self, row: usize, col: usize) -> f32 where
|
||||||
[(); H - 1]: ,
|
[(); H - 1]: ,
|
||||||
[(); W - 1]: ,
|
[(); W - 1]: ,
|
||||||
{
|
{
|
||||||
self.sub_matrix(row, col).determinant()
|
let t = self.zero_skip(row);
|
||||||
|
let b = self.bound_skip(row, H - 1);
|
||||||
|
let l = self.zero_skip(col);
|
||||||
|
let r = self.bound_skip(col, W - 1);
|
||||||
|
|
||||||
|
let tl = self.matrix[t][l];
|
||||||
|
let br = self.matrix[b][r];
|
||||||
|
let tr = self.matrix[t][r];
|
||||||
|
let bl = self.matrix[b][l];
|
||||||
|
|
||||||
|
tl * br - tr * bl
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sub_matrix(&self, skip_row: usize, skip_col: usize) -> Matrix<{H - 1}, {W - 1}>
|
pub fn sub_matrix(&self, skip_row: usize, skip_col: usize) -> Matrix<{H - 1}, {W - 1}>
|
||||||
|
|||||||
Reference in New Issue
Block a user