forked from M-Labs/nalgebra
apply fmt
This commit is contained in:
parent
daade1cf5e
commit
a4e28a136e
@ -1,15 +1,12 @@
|
||||
//! this module implements parallelators to make matrices work with
|
||||
//! the rayon crate seamlessly
|
||||
|
||||
use core::fmt::Debug;
|
||||
use rayon::{
|
||||
iter::plumbing::{bridge},
|
||||
prelude::*,
|
||||
};
|
||||
use crate::{
|
||||
iter::{ColumnIter, ColumnIterMut}, Dim, Matrix, MatrixSlice, MatrixSliceMut,
|
||||
RawStorage, RawStorageMut, U1,
|
||||
iter::{ColumnIter, ColumnIterMut},
|
||||
Dim, Matrix, MatrixSlice, MatrixSliceMut, RawStorage, RawStorageMut, U1,
|
||||
};
|
||||
use core::fmt::Debug;
|
||||
use rayon::{iter::plumbing::bridge, prelude::*};
|
||||
|
||||
/// A rayon parallel iterator over the colums of a matrix
|
||||
pub struct ParColumnIter<'a, T, R: Dim, Cols: Dim, S: RawStorage<T, R, Cols>> {
|
||||
@ -78,28 +75,41 @@ where
|
||||
}
|
||||
|
||||
/// A rayon parallel iterator through the mutable columns of a matrix
|
||||
pub struct ParColumnIterMut<'a,T,R:Dim ,Cols:Dim, S:RawStorage<T,R,Cols>+RawStorageMut<T,R,Cols>> {
|
||||
pub struct ParColumnIterMut<
|
||||
'a,
|
||||
T,
|
||||
R: Dim,
|
||||
Cols: Dim,
|
||||
S: RawStorage<T, R, Cols> + RawStorageMut<T, R, Cols>,
|
||||
> {
|
||||
mat: &'a mut Matrix<T, R, Cols, S>,
|
||||
}
|
||||
|
||||
impl<'a, T, R, Cols, S> ParColumnIterMut<'a, T, R, Cols, S>
|
||||
where R: Dim, Cols : Dim, S:RawStorage<T,R,Cols> + RawStorageMut<T,R,Cols> {
|
||||
where
|
||||
R: Dim,
|
||||
Cols: Dim,
|
||||
S: RawStorage<T, R, Cols> + RawStorageMut<T, R, Cols>,
|
||||
{
|
||||
/// create a new parallel iterator for the given matrix
|
||||
fn new(mat: &'a mut Matrix<T, R, Cols, S>) -> Self {
|
||||
Self {
|
||||
mat,
|
||||
}
|
||||
Self { mat }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T, R, Cols, S> ParallelIterator for ParColumnIterMut<'a, T, R, Cols, S>
|
||||
where R: Dim, Cols : Dim, S:RawStorage<T,R,Cols> + RawStorageMut<T,R,Cols>,
|
||||
where
|
||||
R: Dim,
|
||||
Cols: Dim,
|
||||
S: RawStorage<T, R, Cols> + RawStorageMut<T, R, Cols>,
|
||||
T: Send + Sync + Debug + PartialEq + Clone + 'static,
|
||||
S : Send + Sync {
|
||||
S: Send + Sync,
|
||||
{
|
||||
type Item = MatrixSliceMut<'a, T, R, U1, S::RStride, S::CStride>;
|
||||
fn drive_unindexed<C>(self, consumer: C) -> C::Result
|
||||
where
|
||||
C: rayon::iter::plumbing::UnindexedConsumer<Self::Item> {
|
||||
C: rayon::iter::plumbing::UnindexedConsumer<Self::Item>,
|
||||
{
|
||||
bridge(self, consumer)
|
||||
}
|
||||
|
||||
@ -108,11 +118,14 @@ S : Send + Sync {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<'a, T, R, Cols, S> IndexedParallelIterator for ParColumnIterMut<'a, T, R, Cols, S>
|
||||
where R: Dim, Cols : Dim, S:RawStorage<T,R,Cols> + RawStorageMut<T,R,Cols>,
|
||||
where
|
||||
R: Dim,
|
||||
Cols: Dim,
|
||||
S: RawStorage<T, R, Cols> + RawStorageMut<T, R, Cols>,
|
||||
T: Send + Sync + Debug + PartialEq + Clone + 'static,
|
||||
S : Send + Sync {
|
||||
S: Send + Sync,
|
||||
{
|
||||
fn drive<C: rayon::iter::plumbing::Consumer<Self::Item>>(self, consumer: C) -> C::Result {
|
||||
bridge(self, consumer)
|
||||
}
|
||||
@ -121,13 +134,17 @@ S : Send + Sync {
|
||||
self.mat.ncols()
|
||||
}
|
||||
|
||||
fn with_producer<CB: rayon::iter::plumbing::ProducerCallback<Self::Item>>(self, callback: CB) -> CB::Output {
|
||||
fn with_producer<CB: rayon::iter::plumbing::ProducerCallback<Self::Item>>(
|
||||
self,
|
||||
callback: CB,
|
||||
) -> CB::Output {
|
||||
let producer = ColumnIterMut::new(self.mat);
|
||||
callback.callback(producer)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T, R: Dim, Cols: Dim, S: RawStorage<T, R, Cols> + RawStorageMut<T,R,Cols>> Matrix<T, R, Cols, S>
|
||||
impl<'a, T, R: Dim, Cols: Dim, S: RawStorage<T, R, Cols> + RawStorageMut<T, R, Cols>>
|
||||
Matrix<T, R, Cols, S>
|
||||
where
|
||||
T: Send + Sync + Clone + Debug + PartialEq + 'static,
|
||||
S: Sync,
|
||||
|
@ -1201,8 +1201,8 @@ fn column_iteration_double_ended() {
|
||||
|
||||
#[test]
|
||||
fn parallel_column_iteration() {
|
||||
use nalgebra::dmatrix;
|
||||
use rayon::prelude::*;
|
||||
use nalgebra::{dmatrix,dvector};
|
||||
let dmat: DMatrix<f64> = dmatrix![
|
||||
13.,14.;
|
||||
23.,24.;
|
||||
@ -1220,7 +1220,6 @@ fn parallel_column_iteration() {
|
||||
assert_eq!(par_result, ser_result);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn colum_iteration_mut_double_ended() {
|
||||
let dmat = nalgebra::dmatrix![
|
||||
@ -1244,8 +1243,14 @@ fn parallel_column_iteration_mut() {
|
||||
use rayon::prelude::*;
|
||||
let mut first = DMatrix::<f32>::zeros(400, 300);
|
||||
let mut second = DMatrix::<f32>::zeros(400, 300);
|
||||
first.column_iter_mut().enumerate().for_each(|(idx,mut col)|col[idx]=1.);
|
||||
second.par_column_iter_mut().enumerate().for_each(|(idx,mut col)| col[idx]=1.);
|
||||
first
|
||||
.column_iter_mut()
|
||||
.enumerate()
|
||||
.for_each(|(idx, mut col)| col[idx] = 1.);
|
||||
second
|
||||
.par_column_iter_mut()
|
||||
.enumerate()
|
||||
.for_each(|(idx, mut col)| col[idx] = 1.);
|
||||
assert_eq!(first, second);
|
||||
assert_eq!(second, DMatrix::identity(400, 300));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user