array_matrix/matrix/
submatrix.rs1use crate::matrix::matrix_init;
2
3use super::Matrix;
4
5pub trait Submatrix<O>: Matrix
6where
7 O: Matrix
8{
9 type Index;
10 fn submatrix(&self, index: Self::Index) -> O;
33}
34
35
36impl<F: Clone, const L: usize, const H: usize> Submatrix<[[F; L - 1]; H]> for [[F; L]; H]
37where
38 Self: Matrix,
39 [[F; L - 1]; H]: Matrix
40{
41 type Index = usize;
42
43 fn submatrix(&self, r: usize) -> [[F; L - 1]; H]
44 {
45 matrix_init(|i, j| self[(i + r + 1)%H][j].clone())
46 }
47}
48
49impl<F: Clone, const L: usize, const H: usize> Submatrix<[[F; L]; H - 1]> for [[F; L]; H]
50where
51 Self: Matrix,
52 [[F; L]; H - 1]: Matrix
53{
54 type Index = usize;
55
56 fn submatrix(&self, c: usize) -> [[F; L]; H - 1]
57 {
58 matrix_init(|i, j| self[i][(j + c + 1)%L].clone())
59 }
60}
61
62impl<F: Clone, const L: usize, const H: usize> Submatrix<[[F; L - 1]; H - 1]> for [[F; L]; H]
63where
64 Self: Matrix,
65 [[F; L - 1]; H - 1]: Matrix
66{
67 type Index = (usize, usize);
68
69 fn submatrix(&self, rc: (usize, usize)) -> [[F; L - 1]; H - 1]
70 {
71 matrix_init(|i, j| self[(i + rc.0 + 1)%H][(j + rc.1 + 1)%L].clone())
72 }
73}