array_matrix/matrix/minor.rs
1use crate::Matrix;
2
3use super::det::Det;
4use super::submatrix::Submatrix;
5
6pub trait Minor: Matrix
7{
8 type Index;
9 type Output;
10
11 /// Returns the determinant of the submatrix of a given cell
12 ///
13 /// |Mᵢⱼ|
14 ///
15 /// # Arguments
16 ///
17 /// * `index` - Row and/or collumn to neglect
18 ///
19 /// # Examples
20 ///
21 /// ```rust
22 /// let a = [
23 /// [1.0, 2.0, 3.0],
24 /// [4.0, 5.0, 6.0],
25 /// [7.0, 8.0, 9.0]
26 /// ];
27 /// let m = [
28 /// [5.0, 6.0],
29 /// [8.0, 9.0]
30 /// ].det();
31 /// assert_eq!(a.minor((0, 0)), m);
32 /// ```
33 fn minor(&self, index: Self::Index) -> Self::Output;
34}
35
36impl<F, const N: usize> Minor for [[F; N]; N]
37where
38 Self: Submatrix<[[F; N - 1]; N - 1], Index = (usize, usize)>,
39 [[F; N - 1]; N - 1]: Det
40{
41 type Index = <Self as Submatrix<[[F; N - 1]; N - 1]>>::Index;
42 type Output = <[[F; N - 1]; N - 1] as Det>::Output;
43 fn minor(&self, index: Self::Index) -> Self::Output
44 {
45 self.submatrix(index).det()
46 }
47}
48
49/*impl<F, const N: usize> Minor for [[F; N - 1]; N]
50where
51 Self: Submatrix<[[F; N - 1]; N - 1], Index = usize>,
52 [[F; N - 1]; N - 1]: Det
53{
54 type Index = <Self as Submatrix<[[F; N - 1]; N - 1]>>::Index;
55 type Output = <[[F; N - 1]; N - 1] as Det>::Output;
56 fn minor(&self, index: Self::Index) -> Self::Output
57 {
58 self.submatrix(index).det()
59 }
60}
61
62impl<F, const N: usize> Minor for [[F; N]; N - 1]
63where
64 Self: Submatrix<[[F; N - 1]; N - 1], Index = usize>,
65 [[F; N - 1]; N - 1]: Det
66{
67 type Index = <Self as Submatrix<[[F; N - 1]; N - 1]>>::Index;
68 type Output = <[[F; N - 1]; N - 1] as Det>::Output;
69 fn minor(&self, index: Self::Index) -> Self::Output
70 {
71 self.submatrix(index).det()
72 }
73}*/