fmt
This commit is contained in:
parent
61abece7af
commit
50e25c57f7
|
@ -8,8 +8,8 @@ use crate::{
|
||||||
iter::{ColumnIter, ColumnIterMut},
|
iter::{ColumnIter, ColumnIterMut},
|
||||||
Dim, Matrix, MatrixSlice, MatrixSliceMut, RawStorage, RawStorageMut, Scalar, U1,
|
Dim, Matrix, MatrixSlice, MatrixSliceMut, RawStorage, RawStorageMut, Scalar, U1,
|
||||||
};
|
};
|
||||||
use rayon::{iter::plumbing::bridge, prelude::*};
|
|
||||||
use rayon::iter::plumbing::Producer;
|
use rayon::iter::plumbing::Producer;
|
||||||
|
use rayon::{iter::plumbing::bridge, prelude::*};
|
||||||
|
|
||||||
/// A rayon parallel iterator over the colums of a matrix. It is created
|
/// A rayon parallel iterator over the colums of a matrix. It is created
|
||||||
/// using the [`par_column_iter`] method of [`Matrix`].
|
/// using the [`par_column_iter`] method of [`Matrix`].
|
||||||
|
@ -224,14 +224,15 @@ where
|
||||||
/// a private helper newtype that wraps the `ColumnIter` and implements
|
/// a private helper newtype that wraps the `ColumnIter` and implements
|
||||||
/// the rayon `Producer` trait. It's just here so we don't have to make the
|
/// the rayon `Producer` trait. It's just here so we don't have to make the
|
||||||
/// rayon trait part of the public interface of the `ColumnIter`
|
/// rayon trait part of the public interface of the `ColumnIter`
|
||||||
struct ColumnProducer<'a,T,R:Dim,C:Dim,S:RawStorage<T,R,C>>(ColumnIter<'a,T,R,C,S>);
|
struct ColumnProducer<'a, T, R: Dim, C: Dim, S: RawStorage<T, R, C>>(ColumnIter<'a, T, R, C, S>);
|
||||||
|
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "par-iter")))]
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "par-iter")))]
|
||||||
/// *only available if compiled with the feature `par-iter`*
|
/// *only available if compiled with the feature `par-iter`*
|
||||||
impl<'a, T, R: Dim, Cols: Dim, S: RawStorage<T, R, Cols>> Producer for ColumnProducer<'a, T, R, Cols, S>
|
impl<'a, T, R: Dim, Cols: Dim, S: RawStorage<T, R, Cols>> Producer
|
||||||
|
for ColumnProducer<'a, T, R, Cols, S>
|
||||||
where
|
where
|
||||||
T: Send + Sync + Scalar,
|
T: Send + Sync + Scalar,
|
||||||
S: Sync,
|
S: Sync,
|
||||||
{
|
{
|
||||||
type Item = MatrixSlice<'a, T, R, U1, S::RStride, S::CStride>;
|
type Item = MatrixSlice<'a, T, R, U1, S::RStride, S::CStride>;
|
||||||
type IntoIter = ColumnIter<'a, T, R, Cols, S>;
|
type IntoIter = ColumnIter<'a, T, R, Cols, S>;
|
||||||
|
@ -260,13 +261,15 @@ S: Sync,
|
||||||
|
|
||||||
/// See `ColumnProducer`. A private wrapper newtype that keeps the Producer
|
/// See `ColumnProducer`. A private wrapper newtype that keeps the Producer
|
||||||
/// implementation private
|
/// implementation private
|
||||||
struct ColumnProducerMut<'a, T, R: Dim, C: Dim, S: RawStorageMut<T, R, C>>(ColumnIterMut<'a,T,R,C,S>);
|
struct ColumnProducerMut<'a, T, R: Dim, C: Dim, S: RawStorageMut<T, R, C>>(
|
||||||
|
ColumnIterMut<'a, T, R, C, S>,
|
||||||
|
);
|
||||||
|
|
||||||
impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorageMut<T, R, C>> Producer
|
impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorageMut<T, R, C>> Producer
|
||||||
for ColumnProducerMut<'a, T, R, C, S>
|
for ColumnProducerMut<'a, T, R, C, S>
|
||||||
where
|
where
|
||||||
T: Send + Sync + Scalar,
|
T: Send + Sync + Scalar,
|
||||||
S: Send + Sync,
|
S: Send + Sync,
|
||||||
{
|
{
|
||||||
type Item = MatrixSliceMut<'a, T, R, U1, S::RStride, S::CStride>;
|
type Item = MatrixSliceMut<'a, T, R, U1, S::RStride, S::CStride>;
|
||||||
type IntoIter = ColumnIterMut<'a, T, R, C, S>;
|
type IntoIter = ColumnIterMut<'a, T, R, C, S>;
|
||||||
|
@ -294,10 +297,9 @@ S: Send + Sync,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// this implementation is safe because we are enforcing exclusive access
|
/// this implementation is safe because we are enforcing exclusive access
|
||||||
/// to the columns through the active range of the iterator
|
/// to the columns through the active range of the iterator
|
||||||
unsafe impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + RawStorageMut<T, R, C>> Send
|
unsafe impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + RawStorageMut<T, R, C>> Send
|
||||||
for ColumnIterMut<'a, T, R, C, S>
|
for ColumnIterMut<'a, T, R, C, S>
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -1240,12 +1240,14 @@ fn parallel_column_iteration() {
|
||||||
|
|
||||||
// repeat this test using mutable iterators
|
// repeat this test using mutable iterators
|
||||||
let mut dmat = dmat;
|
let mut dmat = dmat;
|
||||||
dmat.par_column_iter_mut().enumerate().for_each(|(idx, col)| {
|
dmat.par_column_iter_mut()
|
||||||
|
.enumerate()
|
||||||
|
.for_each(|(idx, col)| {
|
||||||
assert_eq!(col, cloned.column(idx));
|
assert_eq!(col, cloned.column(idx));
|
||||||
});
|
});
|
||||||
|
|
||||||
let par_mut_result: f64 = dmat.par_column_iter_mut().map(|col| col.norm()).sum();
|
let par_mut_result: f64 = dmat.par_column_iter_mut().map(|col| col.norm()).sum();
|
||||||
assert_eq!(par_mut_result,ser_result);
|
assert_eq!(par_mut_result, ser_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in New Issue