Bring apply permutation function back to serial.rs

This commit is contained in:
Anton 2021-10-20 20:28:38 +02:00
parent 752d1f300d
commit 89416baace
4 changed files with 11 additions and 14 deletions

View File

@ -14,7 +14,6 @@ use crate::coo::CooMatrix;
use crate::cs; use crate::cs;
use crate::csc::CscMatrix; use crate::csc::CscMatrix;
use crate::csr::CsrMatrix; use crate::csr::CsrMatrix;
use crate::utils::apply_permutation;
/// Converts a dense matrix to [`CooMatrix`]. /// Converts a dense matrix to [`CooMatrix`].
pub fn convert_dense_coo<T, R, C, S>(dense: &Matrix<T, R, C, S>) -> CooMatrix<T> pub fn convert_dense_coo<T, R, C, S>(dense: &Matrix<T, R, C, S>) -> CooMatrix<T>
@ -391,6 +390,15 @@ fn sort_lane<T: Clone>(
apply_permutation(values_result, values, permutation); apply_permutation(values_result, values, permutation);
} }
// TODO: Move this into `utils` or something?
fn apply_permutation<T: Clone>(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 /// 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. /// associative combiner and calls the provided produce methods with combined indices and values.
fn combine_duplicates<T: Clone>( fn combine_duplicates<T: Clone>(

View File

@ -227,7 +227,8 @@ impl<T> CsrMatrix<T> {
} }
// permute indices // permute indices
let sorted_col_indices: Vec<usize> = Vec::from_iter((p.iter().map(|i| &col_indices[*i])).cloned()); let sorted_col_indices: Vec<usize> =
Vec::from_iter((p.iter().map(|i| &col_indices[*i])).cloned());
// permute values // permute values
let sorted_values: Vec<T> = Vec::from_iter((p.iter().map(|i| &values[*i])).cloned()); let sorted_values: Vec<T> = Vec::from_iter((p.iter().map(|i| &values[*i])).cloned());

View File

@ -151,7 +151,6 @@ pub mod ops;
pub mod pattern; pub mod pattern;
pub(crate) mod cs; pub(crate) mod cs;
pub(crate) mod utils;
#[cfg(feature = "proptest-support")] #[cfg(feature = "proptest-support")]
pub mod proptest; pub mod proptest;

View File

@ -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<T: Clone>(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();
}
}