You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/gf2_matrix.rs
+40-55Lines changed: 40 additions & 55 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
-
usecrate::matrix::{MatrixTrait,Matrix};
1
+
usecrate::matrix::{Matrix,MatrixTrait};
2
2
3
3
/// GF(2) matrix.
4
-
///
4
+
///
5
5
/// Implements the trait MatrixTrait: needs to implement
6
6
/// - rank
7
7
/// - kernel
@@ -11,16 +11,15 @@ use crate::matrix::{MatrixTrait, Matrix};
11
11
pubtypeGF2Matrix = Matrix<u8>;
12
12
13
13
implMatrixTrait<u8>forGF2Matrix{
14
-
15
14
/// Checks if a GF(2) matrix is in reduced row echelon form (RREF).
16
15
///
17
16
/// # Returns
18
17
/// `true` if the matrix is in reduced row echelon form; otherwise, `false`.
19
-
fnis_reduced_echelon(&self) -> bool{
18
+
fnis_reduced_echelon(&self) -> bool{
20
19
let nrows = self.nrows();
21
20
letmut old_piv = 0;
22
21
letmut found_zero_row = false;
23
-
for i in0..nrows{
22
+
for i in0..nrows{
24
23
let piv = GF2Matrix::get_pivot(&self.elements[i]);
25
24
match piv {
26
25
None => {
@@ -37,30 +36,27 @@ impl MatrixTrait<u8> for GF2Matrix {
37
36
}
38
37
}
39
38
old_piv = piv;
40
-
41
39
}
42
40
}
43
41
}
44
42
returntrue;
45
43
}
46
44
47
45
/// Computes the rank of the linear applocation represented by a GF(2) matrix.
48
-
///
46
+
///
49
47
/// If the matrix is not in echelon form (RREF),
50
48
/// it first converts the matrix to its RREF before computing the rank.
51
-
///
49
+
///
52
50
/// # Returns
53
51
/// An integer representing the rank of the matrix.
54
52
///
55
-
fnrank(&self) -> usize{
56
-
ifself.is_reduced_echelon(){
57
-
returnself.rank_echelon_form()
58
-
}
59
-
else{
53
+
fnrank(&self) -> usize{
54
+
ifself.is_reduced_echelon(){
55
+
returnself.rank_echelon_form();
56
+
}else{
60
57
let(ech_form, _) = self.echelon_form();
61
-
return ech_form.rank_echelon_form();
58
+
return ech_form.rank_echelon_form();
62
59
}
63
-
64
60
}
65
61
66
62
/// Computes the base of the kernel of the linear applocation represented by a GF(2) matrix.
@@ -70,27 +66,26 @@ impl MatrixTrait<u8> for GF2Matrix {
70
66
///
71
67
/// # Returns
72
68
/// A vector of row vectors, each representing a basis vector of the kernel.
73
-
fnkernel(&self)-> Vec<Vec<u8>>{
74
-
ifself.is_reduced_echelon(){
69
+
fnkernel(&self)-> Vec<Vec<u8>>{
70
+
ifself.is_reduced_echelon(){
75
71
println!("{:?}",self.elements);
76
72
returnself.kernel_echelon_form();
77
-
}
78
-
else{
73
+
}else{
79
74
let(ech_form, _) = self.echelon_form();
80
75
println!("{:?}", ech_form);
81
76
return ech_form.kernel_echelon_form();
82
77
}
83
78
}
84
79
85
80
/// Computes the reduced echelon form (RREF) of a GF(2) matrix along with the history of all row operations applied.
86
-
///
81
+
///
87
82
/// # Returns
88
-
/// A tuple where the first element is the RREF form of the matrix and
83
+
/// A tuple where the first element is the RREF form of the matrix and
89
84
/// the second is a Vec containing the history of the row operations applied to the matrix to compute the RREF.
90
85
/// Each element of the row operations vector, is a tuple heving the modified row as first element and the row to which it has been summed as second element:
91
86
/// R1 -> R1 + R2 is represented the entry (R1, R2)
92
87
/// The swap of two rows is represented as 3 entries:
93
-
/// swap(R1, R2) is represented as (R1, R2), (R2,R1), (R1,R2)
88
+
/// swap(R1, R2) is represented as (R1, R2), (R2,R1), (R1,R2)
0 commit comments