Skip to content

Commit

Permalink
DOC: Update example and docs for whole_chunks_mut
Browse files Browse the repository at this point in the history
  • Loading branch information
bluss committed Mar 30, 2017
1 parent da7057f commit 709aa13
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
28 changes: 26 additions & 2 deletions src/impl_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,8 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, 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<A, D>`
/// The produced element is a `ArrayView<A, D>` with exactly the dimension
/// `chunk_size`.
///
/// **Panics** if any dimension of `chunk_size` is zero<br>
/// (**Panics** if `D` is `IxDyn` and `chunk_size` does not match the
Expand All @@ -637,11 +638,34 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, 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<A, D>`
/// The produced element is a `ArrayViewMut<A, D>` with exactly
/// the dimension `chunk_size`.
///
/// **Panics** if any dimension of `chunk_size` is zero<br>
/// (**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((7, 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],
/// [0, 0, 0, 0, 0, 0, 0]]));
/// ```
pub fn whole_chunks_mut<E>(&mut self, chunk_size: E) -> WholeChunksMut<A, D>
where E: IntoDimension<Dim=D>,
S: DataMut
Expand Down
4 changes: 2 additions & 2 deletions src/iterators/chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down

0 comments on commit 709aa13

Please sign in to comment.