Skip to content

Commit

Permalink
use Vec<u32> as the permutation vector
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbull committed Dec 6, 2024
1 parent 47d2962 commit 153aea7
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/tensors/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,15 +714,15 @@ impl<F: Ring> Matrix<F> {
}
}

pub fn permute_rows(&self, pv: &Vector<Z>) -> Self {
pub fn permute_rows(&self, pv: &Vec<u32>) -> Self {

This comment has been minimized.

Copy link
@benruijl

benruijl Dec 6, 2024

Owner

The canonical way in Rust is &[u32]

assert_eq!(
self.nrows as usize,
pv.len(),
"Permutation vector length must equal the number of rows."
);

let mut data = Vec::with_capacity(self.data.len());
for row_index in &pv.data {
for row_index in pv {
assert!(
row_index.lt(&Integer::from(self.nrows)),
"Row index out of bounds in permutation vector."
Expand Down Expand Up @@ -1241,7 +1241,7 @@ impl<F: Field> Matrix<F> {
fn lu_decomposition(
&self,
early_return: bool,
) -> Result<(Self, Self, Vector<Z>), MatrixError<F>> {
) -> Result<(Self, Self, Vec<u32>), MatrixError<F>> {
let mut u = self.clone();
let (l, p) = u.lu_decomposition_in_place(early_return)?;
Ok((l, u, p))
Expand All @@ -1252,13 +1252,13 @@ impl<F: Field> Matrix<F> {
fn lu_decomposition_in_place(
&mut self,
early_return: bool,
) -> Result<(Self, Vector<Z>), MatrixError<F>> {
) -> Result<(Self, Vec<u32>), MatrixError<F>> {
let one = self.field.one();

let (_, steps) = self.gaussian_elimination_ex(self.ncols as u32, early_return, true)?;
let steps = steps.expect("Internal Error: steps must be Some");

let mut pv: Vec<usize> = (0..self.nrows as usize).collect();
let mut pv: Vec<u32> = (0..self.nrows).collect();
for &(i, k, ref multiplier) in &steps {
if *multiplier == one {
pv.swap(i as usize, k as usize);
Expand All @@ -1272,11 +1272,7 @@ impl<F: Field> Matrix<F> {
}
}

let mut p_data = Vec::new();
for el in pv {
p_data.push(Integer::from(el));
}
Ok((l, Vector::new(p_data, Z)))
Ok((l, pv))
}

/// Write the matrix in echelon form.
Expand Down

0 comments on commit 153aea7

Please sign in to comment.