change feature name to par-iter and add doc example to par_column_iter_mut
This commit is contained in:
parent
97861c8a5e
commit
8d1f684e45
|
@ -33,7 +33,7 @@ libm = [ "simba/libm" ]
|
||||||
libm-force = [ "simba/libm_force" ]
|
libm-force = [ "simba/libm_force" ]
|
||||||
macros = [ "nalgebra-macros" ]
|
macros = [ "nalgebra-macros" ]
|
||||||
cuda = [ "cust_core", "simba/cuda" ]
|
cuda = [ "cust_core", "simba/cuda" ]
|
||||||
rayon = [ "std", "dep:rayon" ]
|
par-iter = [ "std", "rayon" ]
|
||||||
|
|
||||||
# Conversion
|
# Conversion
|
||||||
convert-mint = [ "mint" ]
|
convert-mint = [ "mint" ]
|
||||||
|
|
|
@ -440,7 +440,7 @@ impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + RawStorageMut<T, R, C>> DoubleEndedI
|
||||||
}
|
}
|
||||||
|
|
||||||
/// implementations for parallel iteration with rayon
|
/// implementations for parallel iteration with rayon
|
||||||
#[cfg(feature = "rayon")]
|
#[cfg(feature = "par-iter")]
|
||||||
mod parallel {
|
mod parallel {
|
||||||
use super::*;
|
use super::*;
|
||||||
use rayon::iter::plumbing::Producer;
|
use rayon::iter::plumbing::Producer;
|
||||||
|
|
|
@ -100,7 +100,7 @@ pub type MatrixCross<T, R1, C1, R2, C2> =
|
||||||
/// - [Find the min and max components (vector-specific methods) <span style="float:right;">`argmin`, `argmax`, `icamin`, `icamax`…</span>](#find-the-min-and-max-components-vector-specific-methods)
|
/// - [Find the min and max components (vector-specific methods) <span style="float:right;">`argmin`, `argmax`, `icamin`, `icamax`…</span>](#find-the-min-and-max-components-vector-specific-methods)
|
||||||
///
|
///
|
||||||
/// #### Iteration, map, and fold
|
/// #### Iteration, map, and fold
|
||||||
/// - [Iteration on components, rows, and columns <span style="float:right;">`iter`, `column_iter`…</span>](#iteration-on-components-rows-and-columns)
|
/// - [Iteration on components, rows, and columns <span style="float:right;">`iter`, `column_iter`, `par_column_iter`…</span>](#iteration-on-components-rows-and-columns)
|
||||||
/// - [Elementwise mapping and folding <span style="float:right;">`map`, `fold`, `zip_map`…</span>](#elementwise-mapping-and-folding)
|
/// - [Elementwise mapping and folding <span style="float:right;">`map`, `fold`, `zip_map`…</span>](#elementwise-mapping-and-folding)
|
||||||
/// - [Folding or columns and rows <span style="float:right;">`compress_rows`, `compress_columns`…</span>](#folding-on-columns-and-rows)
|
/// - [Folding or columns and rows <span style="float:right;">`compress_rows`, `compress_columns`…</span>](#folding-on-columns-and-rows)
|
||||||
///
|
///
|
||||||
|
|
|
@ -42,7 +42,8 @@ mod min_max;
|
||||||
/// Mechanisms for working with values that may not be initialized.
|
/// Mechanisms for working with values that may not be initialized.
|
||||||
pub mod uninit;
|
pub mod uninit;
|
||||||
|
|
||||||
#[cfg(feature = "rayon")]
|
|
||||||
|
#[cfg(feature = "par-iter")]
|
||||||
pub mod par_iter;
|
pub mod par_iter;
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
#[cfg(feature = "rkyv-serialize-no-std")]
|
||||||
|
|
|
@ -15,7 +15,7 @@ use rayon::{iter::plumbing::bridge, prelude::*};
|
||||||
///
|
///
|
||||||
/// [`par_column_iter`]: crate::Matrix::par_column_iter
|
/// [`par_column_iter`]: crate::Matrix::par_column_iter
|
||||||
/// [`Matrix`]: crate::Matrix
|
/// [`Matrix`]: crate::Matrix
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "rayon")))]
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "par-iter")))]
|
||||||
pub struct ParColumnIter<'a, T, R: Dim, Cols: Dim, S: RawStorage<T, R, Cols>> {
|
pub struct ParColumnIter<'a, T, R: Dim, Cols: Dim, S: RawStorage<T, R, Cols>> {
|
||||||
mat: &'a Matrix<T, R, Cols, S>,
|
mat: &'a Matrix<T, R, Cols, S>,
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ impl<'a, T, R: Dim, Cols: Dim, S: RawStorage<T, R, Cols>> ParColumnIter<'a, T, R
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "rayon")))]
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "par-iter")))]
|
||||||
impl<'a, T, R: Dim, Cols: Dim, S: RawStorage<T, R, Cols>> ParallelIterator
|
impl<'a, T, R: Dim, Cols: Dim, S: RawStorage<T, R, Cols>> ParallelIterator
|
||||||
for ParColumnIter<'a, T, R, Cols, S>
|
for ParColumnIter<'a, T, R, Cols, S>
|
||||||
where
|
where
|
||||||
|
@ -48,7 +48,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "rayon")))]
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "par-iter")))]
|
||||||
impl<'a, T, R: Dim, Cols: Dim, S: RawStorage<T, R, Cols>> IndexedParallelIterator
|
impl<'a, T, R: Dim, Cols: Dim, S: RawStorage<T, R, Cols>> IndexedParallelIterator
|
||||||
for ParColumnIter<'a, T, R, Cols, S>
|
for ParColumnIter<'a, T, R, Cols, S>
|
||||||
where
|
where
|
||||||
|
@ -72,7 +72,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "rayon")))]
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "par-iter")))]
|
||||||
impl<T, R: Dim, Cols: Dim, S: RawStorage<T, R, Cols>> Matrix<T, R, Cols, S>
|
impl<T, R: Dim, Cols: Dim, S: RawStorage<T, R, Cols>> Matrix<T, R, Cols, S>
|
||||||
where
|
where
|
||||||
T: Send + Sync + Scalar,
|
T: Send + Sync + Scalar,
|
||||||
|
@ -83,7 +83,7 @@ where
|
||||||
/// if *mutable* access to the columns is required, use [`par_column_iter_mut`]
|
/// if *mutable* access to the columns is required, use [`par_column_iter_mut`]
|
||||||
/// instead.
|
/// instead.
|
||||||
///
|
///
|
||||||
/// **Example**
|
/// # Example
|
||||||
/// Using parallel column iterators to calculate the sum of the maximum
|
/// Using parallel column iterators to calculate the sum of the maximum
|
||||||
/// elements in each column:
|
/// elements in each column:
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -110,7 +110,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "rayon")))]
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "par-iter")))]
|
||||||
/// A rayon parallel iterator through the mutable columns of a matrix
|
/// A rayon parallel iterator through the mutable columns of a matrix
|
||||||
pub struct ParColumnIterMut<
|
pub struct ParColumnIterMut<
|
||||||
'a,
|
'a,
|
||||||
|
@ -122,7 +122,7 @@ pub struct ParColumnIterMut<
|
||||||
mat: &'a mut Matrix<T, R, Cols, S>,
|
mat: &'a mut Matrix<T, R, Cols, S>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "rayon")))]
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "par-iter")))]
|
||||||
impl<'a, T, R, Cols, S> ParColumnIterMut<'a, T, R, Cols, S>
|
impl<'a, T, R, Cols, S> ParColumnIterMut<'a, T, R, Cols, S>
|
||||||
where
|
where
|
||||||
R: Dim,
|
R: Dim,
|
||||||
|
@ -135,7 +135,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "rayon")))]
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "par-iter")))]
|
||||||
impl<'a, T, R, Cols, S> ParallelIterator for ParColumnIterMut<'a, T, R, Cols, S>
|
impl<'a, T, R, Cols, S> ParallelIterator for ParColumnIterMut<'a, T, R, Cols, S>
|
||||||
where
|
where
|
||||||
R: Dim,
|
R: Dim,
|
||||||
|
@ -157,7 +157,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "rayon")))]
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "par-iter")))]
|
||||||
impl<'a, T, R, Cols, S> IndexedParallelIterator for ParColumnIterMut<'a, T, R, Cols, S>
|
impl<'a, T, R, Cols, S> IndexedParallelIterator for ParColumnIterMut<'a, T, R, Cols, S>
|
||||||
where
|
where
|
||||||
R: Dim,
|
R: Dim,
|
||||||
|
@ -183,14 +183,36 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "rayon")))]
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "par-iter")))]
|
||||||
impl<T, R: Dim, Cols: Dim, S: RawStorage<T, R, Cols> + RawStorageMut<T, R, Cols>>
|
impl<T, R: Dim, Cols: Dim, S: RawStorage<T, R, Cols> + RawStorageMut<T, R, Cols>>
|
||||||
Matrix<T, R, Cols, S>
|
Matrix<T, R, Cols, S>
|
||||||
where
|
where
|
||||||
T: Send + Sync + Scalar,
|
T: Send + Sync + Scalar,
|
||||||
S: Sync,
|
S: Sync,
|
||||||
{
|
{
|
||||||
/// Mutably iterate through the columns of this matrix in parallel using rayon
|
/// Mutably iterate through the columns of this matrix in parallel using rayon.
|
||||||
|
/// Allows mutable access to the columns in parallel using mutable references.
|
||||||
|
/// If mutable access to the columns is not required rather use [`par_column_iter`]
|
||||||
|
/// instead.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
/// Normalize each column of a matrix with respect to its own maximum value.
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use nalgebra::{dmatrix,DMatrix};
|
||||||
|
/// use rayon::prelude::*;
|
||||||
|
///
|
||||||
|
/// let mut matrix : DMatrix<f64> =
|
||||||
|
/// dmatrix![2.,4.,6.;
|
||||||
|
/// 1.,2.,3.];
|
||||||
|
/// matrix.par_column_iter_mut().for_each(|mut col| col /= col.max());
|
||||||
|
///
|
||||||
|
/// assert_eq!(matrix,
|
||||||
|
/// dmatrix![1. ,1. , 1.;
|
||||||
|
/// 0.5,0.5,0.5]);
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// [`par_column_iter`]: crate::Matrix::par_column_iter
|
||||||
pub fn par_column_iter_mut(&mut self) -> ParColumnIterMut<'_, T, R, Cols, S> {
|
pub fn par_column_iter_mut(&mut self) -> ParColumnIterMut<'_, T, R, Cols, S> {
|
||||||
ParColumnIterMut::new(self)
|
ParColumnIterMut::new(self)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1200,7 +1200,7 @@ fn column_iteration_double_ended() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "rayon")]
|
#[cfg(feature = "par-iter")]
|
||||||
fn parallel_column_iteration() {
|
fn parallel_column_iteration() {
|
||||||
use nalgebra::dmatrix;
|
use nalgebra::dmatrix;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
@ -1222,7 +1222,7 @@ fn parallel_column_iteration() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "rayon")]
|
#[cfg(feature = "par-iter")]
|
||||||
fn column_iteration_mut_double_ended() {
|
fn column_iteration_mut_double_ended() {
|
||||||
let dmat = nalgebra::dmatrix![
|
let dmat = nalgebra::dmatrix![
|
||||||
13,14,15,16,17;
|
13,14,15,16,17;
|
||||||
|
@ -1241,7 +1241,7 @@ fn column_iteration_mut_double_ended() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "rayon")]
|
#[cfg(feature = "par-iter")]
|
||||||
fn parallel_column_iteration_mut() {
|
fn parallel_column_iteration_mut() {
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
let mut first = DMatrix::<f32>::zeros(400, 300);
|
let mut first = DMatrix::<f32>::zeros(400, 300);
|
||||||
|
|
|
@ -10,8 +10,8 @@ compile_error!(
|
||||||
);
|
);
|
||||||
|
|
||||||
// make sure to test the parallel iterators for all builds that do not require no_std
|
// make sure to test the parallel iterators for all builds that do not require no_std
|
||||||
#[cfg(all(feature = "std", not(feature = "rayon")))]
|
#[cfg(all(feature = "std", not(feature = "par-iter")))]
|
||||||
compile_error!("Please additionally enable the `rayon` feature to compile and run the tests");
|
compile_error!("Please additionally enable the `par-iter` feature to compile and run the tests");
|
||||||
|
|
||||||
#[cfg(all(feature = "debug", feature = "compare", feature = "rand"))]
|
#[cfg(all(feature = "debug", feature = "compare", feature = "rand"))]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|
Loading…
Reference in New Issue