Skip to content

Commit

Permalink
Add Subspace::complement
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyBF committed Jul 6, 2023
1 parent ac82650 commit f747485
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ext/crates/fp/src/matrix/subspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,24 @@ impl Subspace {
}
}

/// Returns a complementary space to `self`.
pub fn complement(&self) -> Subspace {
let dimension = self.ambient_dimension() - self.dimension();
let mut complement = Subspace::new(self.prime(), dimension, self.ambient_dimension());
let mut i = 0;
complement.add_vectors(|mut row| {
while i < self.ambient_dimension() {
i += 1;
if !self.pivots().contains(&(i as isize - 1)) {
row.set_entry(i - 1, 1);
return Some(());
}
}
None
});
complement
}

pub fn contains(&self, vector: Slice) -> bool {
let mut vector: FpVector = vector.into_owned();
self.reduce(vector.as_slice_mut());
Expand Down

0 comments on commit f747485

Please sign in to comment.