From da16e759cd8acb501f0a0f81245a8c258a51f45c Mon Sep 17 00:00:00 2001 From: bluss Date: Thu, 30 Mar 2017 21:48:42 +0200 Subject: [PATCH] DOC: Update example and docs for whole_chunks_mut --- src/impl_methods.rs | 27 +++++++++++++++++++++++++-- src/iterators/chunks.rs | 4 ++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/impl_methods.rs b/src/impl_methods.rs index 436b1d0ea..5af1bfc61 100644 --- a/src/impl_methods.rs +++ b/src/impl_methods.rs @@ -621,7 +621,8 @@ impl ArrayBase where S: Data, D: Dimension /// It produces the whole chunks of a given n-dimensional chunk size, /// skipping the remainder along each dimension that doesn't fit evenly. /// - /// Iterator element is `ArrayView` + /// The produced element is a `ArrayView` with exactly the dimension + /// `chunk_size`. /// /// **Panics** if any dimension of `chunk_size` is zero
/// (**Panics** if `D` is `IxDyn` and `chunk_size` does not match the @@ -637,11 +638,33 @@ impl ArrayBase where S: Data, D: Dimension /// It produces the whole chunks of a given n-dimensional chunk size, /// skipping the remainder along each dimension that doesn't fit evenly. /// - /// Iterator element is `ArrayViewMut` + /// The produced element is a `ArrayViewMut` with exactly + /// the dimension `chunk_size`. /// /// **Panics** if any dimension of `chunk_size` is zero
/// (**Panics** if `D` is `IxDyn` and `chunk_size` does not match the /// number of array axes.) + /// + /// ```rust + /// use ndarray::Array; + /// use ndarray::arr2; + /// let mut a = Array::zeros((6, 7)); + /// + /// // Fill each 2 × 2 chunk with the index of where it appeared in iteration + /// for (i, mut chunk) in a.whole_chunks_mut((2, 2)).into_iter().enumerate() { + /// chunk.fill(i); + /// } + /// + /// // The resulting array is: + /// assert_eq!( + /// a, + /// arr2(&[[0, 0, 1, 1, 2, 2, 0], + /// [0, 0, 1, 1, 2, 2, 0], + /// [3, 3, 4, 4, 5, 5, 0], + /// [3, 3, 4, 4, 5, 5, 0], + /// [6, 6, 7, 7, 8, 8, 0], + /// [6, 6, 7, 7, 8, 8, 0]])); + /// ``` pub fn whole_chunks_mut(&mut self, chunk_size: E) -> WholeChunksMut where E: IntoDimension, S: DataMut diff --git a/src/iterators/chunks.rs b/src/iterators/chunks.rs index 9cfbb88ff..c52ad15e0 100644 --- a/src/iterators/chunks.rs +++ b/src/iterators/chunks.rs @@ -108,8 +108,8 @@ impl_ndproducer! { /// Whole chunks producer and iterable. /// -/// See [`.whole_chunks()`](struct.ArrayBase.html#method.whole_chunks) for more -/// information. +/// See [`.whole_chunks_mut()`](struct.ArrayBase.html#method.whole_chunks_mut) +/// for more information. //#[derive(Debug)] pub struct WholeChunksMut<'a, A: 'a, D> { base: BaseProducerMut<'a, A, D>,