From daade1cf5e83cc956ef64b6e8e762cc5260f2705 Mon Sep 17 00:00:00 2001 From: geo-ant <54497890+geo-ant@users.noreply.github.com> Date: Fri, 21 Oct 2022 08:44:35 +0200 Subject: [PATCH] add documentation --- src/base/iter.rs | 15 +++------------ src/base/par_iter.rs | 21 +++++++++------------ 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/base/iter.rs b/src/base/iter.rs index f4b34f63..eb3312c0 100644 --- a/src/base/iter.rs +++ b/src/base/iter.rs @@ -311,15 +311,6 @@ impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorage> ColumnIter<'a, T, R, C, range: 0..mat.ncols(), } } - /// a new column iterator covering column indices [begin,end) - /// where begin is included in the range but index end is not - /// begin must lie in [0,ncols] and end must lie in [0,ncols]. - pub(crate) fn with_range(mat: &'a Matrix, range: Range) -> Self { - debug_assert!(range.end <= mat.ncols()); - debug_assert!(range.start < mat.ncols()); - debug_assert!(range.start <= range.end); - Self { mat, range } - } } impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorage> Iterator for ColumnIter<'a, T, R, C, S> { @@ -384,7 +375,7 @@ where fn split_at(self, index: usize) -> (Self, Self) { // the index is relative to the size of this current iterator - // it will always start at zero + // it will always start at zero so it serves as an offset let left = Self { mat: self.mat, range: self.range.start..(self.range.start + index), @@ -465,7 +456,7 @@ impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + RawStorageMut> DoubleEndedI debug_assert!(self.range.start <= self.range.end); if !self.range.is_empty() { self.range.end -= 1; - debug_assert!(self.range.end < unsafe { (*self.mat).ncols() }); + debug_assert!(self.range.end < self.mat.ncols()); debug_assert!(self.range.end >= self.range.start); let pmat: *mut _ = self.mat; Some(unsafe { (*pmat).column_mut(self.range.end) }) @@ -490,7 +481,7 @@ where fn split_at(self, index: usize) -> (Self, Self) { // the index is relative to the size of this current iterator - // it will always start at zero + // it will always start at zero so it serves as an offset let pmat: *mut _ = self.mat; let left = Self { diff --git a/src/base/par_iter.rs b/src/base/par_iter.rs index b53e1f49..3854e678 100644 --- a/src/base/par_iter.rs +++ b/src/base/par_iter.rs @@ -1,26 +1,23 @@ //! this module implements parallelators to make matrices work with //! the rayon crate seamlessly -use core::{ - fmt::Debug, -}; - +use core::fmt::Debug; use rayon::{ iter::plumbing::{bridge}, prelude::*, }; - use crate::{ - iter::{ColumnIter, ColumnIterMut}, DMatrix, Dim, Matrix, MatrixSlice, MatrixSliceMut, + iter::{ColumnIter, ColumnIterMut}, Dim, Matrix, MatrixSlice, MatrixSliceMut, RawStorage, RawStorageMut, U1, }; -/// a rayon parallel iterator over the columns of a matrix +/// A rayon parallel iterator over the colums of a matrix pub struct ParColumnIter<'a, T, R: Dim, Cols: Dim, S: RawStorage> { mat: &'a Matrix, } impl<'a, T, R: Dim, Cols: Dim, S: RawStorage> ParColumnIter<'a, T, R, Cols, S> { + /// create a new parallel iterator for the given matrix fn new(matrix: &'a Matrix) -> Self { Self { mat: matrix } } @@ -74,21 +71,21 @@ where T: Send + Sync + Clone + Debug + PartialEq + 'static, S: Sync, { - /// TODO + /// Iterate through the columns of the matrix in parallel using rayon. pub fn par_column_iter(&self) -> ParColumnIter<'_, T, R, Cols, S> { ParColumnIter::new(self) } } -/// TODO +/// A rayon parallel iterator through the mutable columns of a matrix pub struct ParColumnIterMut<'a,T,R:Dim ,Cols:Dim, S:RawStorage+RawStorageMut> { mat : &'a mut Matrix, } impl<'a,T,R,Cols,S> ParColumnIterMut<'a,T,R,Cols,S> where R: Dim, Cols : Dim, S:RawStorage + RawStorageMut { - /// TODO - pub fn new(mat : &'a mut Matrix) -> Self { + /// create a new parallel iterator for the given matrix + fn new(mat : &'a mut Matrix) -> Self { Self { mat, } @@ -135,7 +132,7 @@ where T: Send + Sync + Clone + Debug + PartialEq + 'static, S: Sync, { - /// TODO + /// Mutably iterate through the columns of this matrix in parallel using rayon pub fn par_column_iter_mut(&mut self) -> ParColumnIterMut<'_, T, R, Cols, S> { ParColumnIterMut::new(self) }