Skip to content

Commit 4445e5a

Browse files
committed
DOC: Update example and docs for whole_chunks_mut
1 parent b76619d commit 4445e5a

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/impl_methods.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,8 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
621621
/// It produces the whole chunks of a given n-dimensional chunk size,
622622
/// skipping the remainder along each dimension that doesn't fit evenly.
623623
///
624-
/// Iterator element is `ArrayView<A, D>`
624+
/// The produced element is a `ArrayView<A, D>` with exactly the dimension
625+
/// `chunk_size`.
625626
///
626627
/// **Panics** if any dimension of `chunk_size` is zero<br>
627628
/// (**Panics** if `D` is `IxDyn` and `chunk_size` does not match the
@@ -637,11 +638,33 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
637638
/// It produces the whole chunks of a given n-dimensional chunk size,
638639
/// skipping the remainder along each dimension that doesn't fit evenly.
639640
///
640-
/// Iterator element is `ArrayViewMut<A, D>`
641+
/// The produced element is a `ArrayViewMut<A, D>` with exactly
642+
/// the dimension `chunk_size`.
641643
///
642644
/// **Panics** if any dimension of `chunk_size` is zero<br>
643645
/// (**Panics** if `D` is `IxDyn` and `chunk_size` does not match the
644646
/// number of array axes.)
647+
///
648+
/// ```rust
649+
/// use ndarray::Array;
650+
/// use ndarray::arr2;
651+
/// let mut a = Array::zeros((6, 7));
652+
///
653+
/// // Fill each 2 × 2 chunk with the index of where it appeared in iteration
654+
/// for (i, mut chunk) in a.whole_chunks_mut((2, 2)).into_iter().enumerate() {
655+
/// chunk.fill(i);
656+
/// }
657+
///
658+
/// // The resulting array is:
659+
/// assert_eq!(
660+
/// a,
661+
/// arr2(&[[0, 0, 1, 1, 2, 2, 0],
662+
/// [0, 0, 1, 1, 2, 2, 0],
663+
/// [3, 3, 4, 4, 5, 5, 0],
664+
/// [3, 3, 4, 4, 5, 5, 0],
665+
/// [6, 6, 7, 7, 8, 8, 0],
666+
/// [6, 6, 7, 7, 8, 8, 0]]));
667+
/// ```
645668
pub fn whole_chunks_mut<E>(&mut self, chunk_size: E) -> WholeChunksMut<A, D>
646669
where E: IntoDimension<Dim=D>,
647670
S: DataMut

src/iterators/chunks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ impl_ndproducer! {
108108

109109
/// Whole chunks producer and iterable.
110110
///
111-
/// See [`.whole_chunks()`](struct.ArrayBase.html#method.whole_chunks) for more
112-
/// information.
111+
/// See [`.whole_chunks_mut()`](struct.ArrayBase.html#method.whole_chunks_mut)
112+
/// for more information.
113113
//#[derive(Debug)]
114114
pub struct WholeChunksMut<'a, A: 'a, D> {
115115
base: BaseProducerMut<'a, A, D>,

0 commit comments

Comments
 (0)