1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use crate::matrix::matrix_init;
use super::Matrix;
pub trait Submatrix<O>: Matrix
where
O: Matrix
{
type Index;
fn submatrix(&self, index: Self::Index) -> O;
}
impl<F: Copy, const L: usize, const H: usize> Submatrix<[[F; L - 1]; H]> for [[F; L]; H]
where
Self: Matrix,
[[F; L - 1]; H]: Matrix
{
type Index = usize;
fn submatrix(&self, r: usize) -> [[F; L - 1]; H]
{
matrix_init(|i, j| self[(i + r + 1)%H][j])
}
}
impl<F: Copy, const L: usize, const H: usize> Submatrix<[[F; L]; H - 1]> for [[F; L]; H]
where
Self: Matrix,
[[F; L]; H - 1]: Matrix
{
type Index = usize;
fn submatrix(&self, c: usize) -> [[F; L]; H - 1]
{
matrix_init(|i, j| self[i][(j + c + 1)%L])
}
}
impl<F: Copy, const L: usize, const H: usize> Submatrix<[[F; L - 1]; H - 1]> for [[F; L]; H]
where
Self: Matrix,
[[F; L - 1]; H - 1]: Matrix
{
type Index = (usize, usize);
fn submatrix(&self, rc: (usize, usize)) -> [[F; L - 1]; H - 1]
{
matrix_init(|i, j| self[(i + rc.0 + 1)%H][(j + rc.1 + 1)%L])
}
}