add examples in par_column_iter method

This commit is contained in:
geo-ant 2022-11-13 14:54:26 +01:00 committed by Sébastien Crozet
parent 83c2e27d6d
commit 97861c8a5e
2 changed files with 32 additions and 0 deletions

View File

@ -138,3 +138,5 @@ lto = true
[package.metadata.docs.rs] [package.metadata.docs.rs]
# Enable all the features when building the docs on docs.rs # Enable all the features when building the docs on docs.rs
all-features = true all-features = true
# define the configuration attribute `docsrs`
rustdoc-args = ["--cfg", "docsrs"]

View File

@ -1,5 +1,9 @@
//! Parallel iterators for matrices compatible with rayon. //! Parallel iterators for matrices compatible with rayon.
//only enables the `doc_cfg` feature when
// the `docsrs` configuration attribute is defined
#![cfg_attr(docsrs, feature(doc_cfg))]
use crate::{ use crate::{
iter::{ColumnIter, ColumnIterMut}, iter::{ColumnIter, ColumnIterMut},
Dim, Matrix, MatrixSlice, MatrixSliceMut, RawStorage, RawStorageMut, Scalar, U1, Dim, Matrix, MatrixSlice, MatrixSliceMut, RawStorage, RawStorageMut, Scalar, U1,
@ -75,6 +79,32 @@ where
S: Sync, S: Sync,
{ {
/// Iterate through the columns of the matrix in parallel using rayon. /// Iterate through the columns of the matrix in parallel using rayon.
/// This iterates over *immutable* references ot the columns of the matrix,
/// if *mutable* access to the columns is required, use [`par_column_iter_mut`]
/// instead.
///
/// **Example**
/// Using parallel column iterators to calculate the sum of the maximum
/// elements in each column:
/// ```
/// use nalgebra::{dmatrix,DMatrix};
/// use rayon::prelude::*;
///
/// let matrix : DMatrix<f64> =
/// nalgebra::dmatrix![1.,0.,5.;
/// 2.,4.,1.;
/// 3.,2.,2.;];
/// let sum_of_max :f64 =
/// matrix
/// .par_column_iter()
/// .map(|col|col.max())
/// .sum();
///
/// assert_eq!(sum_of_max,3.+4.+5.);
///
/// ```
///
/// [`par_column_iter_mut`]: crate::Matrix::par_column_iter_mut
pub fn par_column_iter(&self) -> ParColumnIter<'_, T, R, Cols, S> { pub fn par_column_iter(&self) -> ParColumnIter<'_, T, R, Cols, S> {
ParColumnIter::new(self) ParColumnIter::new(self)
} }