add documentation

This commit is contained in:
geo-ant 2022-10-21 08:44:35 +02:00 committed by Sébastien Crozet
parent 7ac536be07
commit daade1cf5e
2 changed files with 12 additions and 24 deletions

View File

@ -311,15 +311,6 @@ impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorage<T, R, C>> ColumnIter<'a, T, R, C,
range: 0..mat.ncols(), 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<T, R, C, S>, range: Range<usize>) -> 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<T, R, C>> Iterator for ColumnIter<'a, T, R, C, S> { impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorage<T, R, C>> Iterator for ColumnIter<'a, T, R, C, S> {
@ -384,7 +375,7 @@ where
fn split_at(self, index: usize) -> (Self, Self) { fn split_at(self, index: usize) -> (Self, Self) {
// the index is relative to the size of this current iterator // 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 { let left = Self {
mat: self.mat, mat: self.mat,
range: self.range.start..(self.range.start + index), range: self.range.start..(self.range.start + index),
@ -465,7 +456,7 @@ impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + RawStorageMut<T, R, C>> DoubleEndedI
debug_assert!(self.range.start <= self.range.end); debug_assert!(self.range.start <= self.range.end);
if !self.range.is_empty() { if !self.range.is_empty() {
self.range.end -= 1; 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); debug_assert!(self.range.end >= self.range.start);
let pmat: *mut _ = self.mat; let pmat: *mut _ = self.mat;
Some(unsafe { (*pmat).column_mut(self.range.end) }) Some(unsafe { (*pmat).column_mut(self.range.end) })
@ -490,7 +481,7 @@ where
fn split_at(self, index: usize) -> (Self, Self) { fn split_at(self, index: usize) -> (Self, Self) {
// the index is relative to the size of this current iterator // 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 pmat: *mut _ = self.mat;
let left = Self { let left = Self {

View File

@ -1,26 +1,23 @@
//! this module implements parallelators to make matrices work with //! this module implements parallelators to make matrices work with
//! the rayon crate seamlessly //! the rayon crate seamlessly
use core::{ use core::fmt::Debug;
fmt::Debug,
};
use rayon::{ use rayon::{
iter::plumbing::{bridge}, iter::plumbing::{bridge},
prelude::*, prelude::*,
}; };
use crate::{ use crate::{
iter::{ColumnIter, ColumnIterMut}, DMatrix, Dim, Matrix, MatrixSlice, MatrixSliceMut, iter::{ColumnIter, ColumnIterMut}, Dim, Matrix, MatrixSlice, MatrixSliceMut,
RawStorage, RawStorageMut, U1, 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<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>,
} }
impl<'a, T, R: Dim, Cols: Dim, S: RawStorage<T, R, Cols>> ParColumnIter<'a, T, R, Cols, S> { impl<'a, T, R: Dim, Cols: Dim, S: RawStorage<T, R, Cols>> ParColumnIter<'a, T, R, Cols, S> {
/// create a new parallel iterator for the given matrix
fn new(matrix: &'a Matrix<T, R, Cols, S>) -> Self { fn new(matrix: &'a Matrix<T, R, Cols, S>) -> Self {
Self { mat: matrix } Self { mat: matrix }
} }
@ -74,21 +71,21 @@ where
T: Send + Sync + Clone + Debug + PartialEq + 'static, T: Send + Sync + Clone + Debug + PartialEq + 'static,
S: Sync, 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> { pub fn par_column_iter(&self) -> ParColumnIter<'_, T, R, Cols, S> {
ParColumnIter::new(self) 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<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>, mat : &'a mut Matrix<T,R,Cols,S>,
} }
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 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> {
/// TODO /// create a new parallel iterator for the given matrix
pub fn new(mat : &'a mut Matrix<T,R,Cols,S>) -> Self { fn new(mat : &'a mut Matrix<T,R,Cols,S>) -> Self {
Self { Self {
mat, mat,
} }
@ -135,7 +132,7 @@ where
T: Send + Sync + Clone + Debug + PartialEq + 'static, T: Send + Sync + Clone + Debug + PartialEq + 'static,
S: Sync, 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> { pub fn par_column_iter_mut(&mut self) -> ParColumnIterMut<'_, T, R, Cols, S> {
ParColumnIterMut::new(self) ParColumnIterMut::new(self)
} }