From 89416baacea24b4da17de7223646303ade219623 Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 20 Oct 2021 20:28:38 +0200 Subject: [PATCH] Bring apply permutation function back to serial.rs --- nalgebra-sparse/src/convert/serial.rs | 10 +++++++++- nalgebra-sparse/src/csr.rs | 3 ++- nalgebra-sparse/src/lib.rs | 1 - nalgebra-sparse/src/utils.rs | 11 ----------- 4 files changed, 11 insertions(+), 14 deletions(-) delete mode 100644 nalgebra-sparse/src/utils.rs diff --git a/nalgebra-sparse/src/convert/serial.rs b/nalgebra-sparse/src/convert/serial.rs index 219a6bf7..ecbe1dab 100644 --- a/nalgebra-sparse/src/convert/serial.rs +++ b/nalgebra-sparse/src/convert/serial.rs @@ -14,7 +14,6 @@ use crate::coo::CooMatrix; use crate::cs; use crate::csc::CscMatrix; use crate::csr::CsrMatrix; -use crate::utils::apply_permutation; /// Converts a dense matrix to [`CooMatrix`]. pub fn convert_dense_coo(dense: &Matrix) -> CooMatrix @@ -391,6 +390,15 @@ fn sort_lane( apply_permutation(values_result, values, permutation); } +// TODO: Move this into `utils` or something? +fn apply_permutation(out_slice: &mut [T], in_slice: &[T], permutation: &[usize]) { + assert_eq!(out_slice.len(), in_slice.len()); + assert_eq!(out_slice.len(), permutation.len()); + for (out_element, old_pos) in out_slice.iter_mut().zip(permutation) { + *out_element = in_slice[*old_pos].clone(); + } +} + /// Given *sorted* indices and corresponding scalar values, combines duplicates with the given /// associative combiner and calls the provided produce methods with combined indices and values. fn combine_duplicates( diff --git a/nalgebra-sparse/src/csr.rs b/nalgebra-sparse/src/csr.rs index bbeec1da..4324d18d 100644 --- a/nalgebra-sparse/src/csr.rs +++ b/nalgebra-sparse/src/csr.rs @@ -227,7 +227,8 @@ impl CsrMatrix { } // permute indices - let sorted_col_indices: Vec = Vec::from_iter((p.iter().map(|i| &col_indices[*i])).cloned()); + let sorted_col_indices: Vec = + Vec::from_iter((p.iter().map(|i| &col_indices[*i])).cloned()); // permute values let sorted_values: Vec = Vec::from_iter((p.iter().map(|i| &values[*i])).cloned()); diff --git a/nalgebra-sparse/src/lib.rs b/nalgebra-sparse/src/lib.rs index 64331817..bf845757 100644 --- a/nalgebra-sparse/src/lib.rs +++ b/nalgebra-sparse/src/lib.rs @@ -151,7 +151,6 @@ pub mod ops; pub mod pattern; pub(crate) mod cs; -pub(crate) mod utils; #[cfg(feature = "proptest-support")] pub mod proptest; diff --git a/nalgebra-sparse/src/utils.rs b/nalgebra-sparse/src/utils.rs deleted file mode 100644 index a5da85c5..00000000 --- a/nalgebra-sparse/src/utils.rs +++ /dev/null @@ -1,11 +0,0 @@ -//! Helper functions for sparse matrix computations - -/// permutes entries of in_slice according to permutation slice and puts them to out_slice -#[inline] -pub fn apply_permutation(out_slice: &mut [T], in_slice: &[T], permutation: &[usize]) { - assert_eq!(out_slice.len(), in_slice.len()); - assert_eq!(out_slice.len(), permutation.len()); - for (out_element, old_pos) in out_slice.iter_mut().zip(permutation) { - *out_element = in_slice[*old_pos].clone(); - } -}