Skip to content

Commit e0e19dc

Browse files
author
maxtremblay
committed
Fix error in nullspace algorithm
1 parent c562688 commit e0e19dc

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sparse-bin-mat"
3-
version = "0.2.3"
3+
version = "0.3"
44
authors = ["maxtremblay <maxtremblay>"]
55
edition = "2018"
66
description = "A sparse implementation of a binary matrix optimized for row operations"

src/matrix/nullspace.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ pub(super) fn nullspace(matrix: &SparseBinMat) -> SparseBinMat {
55
let echelon_form = matrix.echelon_form();
66
let (normal_form, permutation) = normal_form_from_echelon_form(&echelon_form);
77
let nullspace = normal_form
8-
.without_columns(&(0..matrix.number_of_rows()).collect_vec())
8+
.without_columns(&(0..normal_form.number_of_rows()).collect_vec())
99
.vertical_concat_with(&SparseBinMat::identity(
10-
matrix.number_of_columns() - matrix.number_of_rows(),
10+
normal_form.number_of_columns() - normal_form.number_of_rows(),
1111
));
1212
permute_columns(&nullspace.transposed(), &inverse_permutation(&permutation))
1313
}
@@ -68,6 +68,13 @@ fn inverse_permutation(permutation: &[usize]) -> Vec<usize> {
6868
mod test {
6969
use super::*;
7070

71+
#[test]
72+
fn nullspace_of_rank_1_matrix() {
73+
let matrix = SparseBinMat::new(4, vec![vec![0, 1, 2, 3]]);
74+
let expected = SparseBinMat::new(4, vec![vec![0, 1], vec![0, 2], vec![0, 3]]);
75+
assert_eq!(nullspace(&matrix), expected);
76+
}
77+
7178
#[test]
7279
fn normal_form() {
7380
let matrix = SparseBinMat::new(6, vec![vec![0, 1, 2], vec![1, 4], vec![3, 4, 5], vec![5]]);

0 commit comments

Comments
 (0)