@@ -22,10 +22,11 @@ use super::zipsl;
22
22
use super :: ZipExt ;
23
23
use dimension:: IntoDimension ;
24
24
use dimension:: { axes_of, Axes , merge_axes, stride_offset} ;
25
- use iterators:: whole_chunks_of;
26
25
use iterators:: {
27
26
new_inner_iter_smaller,
28
27
new_inner_iter_smaller_mut,
28
+ whole_chunks_of,
29
+ whole_chunks_mut_of,
29
30
} ;
30
31
31
32
use {
41
42
AxisIter ,
42
43
AxisIterMut ,
43
44
WholeChunks ,
45
+ WholeChunksMut ,
44
46
} ;
45
47
use stacking:: stack;
46
48
@@ -619,15 +621,57 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
619
621
/// It produces the whole chunks of a given n-dimensional chunk size,
620
622
/// skipping the remainder along each dimension that doesn't fit evenly.
621
623
///
622
- /// Iterator element is `ArrayView<A, D>`
624
+ /// The produced element is a `ArrayView<A, D>` with exactly the dimension
625
+ /// `chunk_size`.
623
626
///
624
- /// **Panics** if any dimension of `chunk_size` is zero
627
+ /// **Panics** if any dimension of `chunk_size` is zero<br>
628
+ /// (**Panics** if `D` is `IxDyn` and `chunk_size` does not match the
629
+ /// number of array axes.)
625
630
pub fn whole_chunks < E > ( & self , chunk_size : E ) -> WholeChunks < A , D >
626
631
where E : IntoDimension < Dim =D > ,
627
632
{
628
633
whole_chunks_of ( self . view ( ) , chunk_size)
629
634
}
630
635
636
+ /// Return a whole chunks producer (and iterable).
637
+ ///
638
+ /// It produces the whole chunks of a given n-dimensional chunk size,
639
+ /// skipping the remainder along each dimension that doesn't fit evenly.
640
+ ///
641
+ /// The produced element is a `ArrayViewMut<A, D>` with exactly
642
+ /// the dimension `chunk_size`.
643
+ ///
644
+ /// **Panics** if any dimension of `chunk_size` is zero<br>
645
+ /// (**Panics** if `D` is `IxDyn` and `chunk_size` does not match the
646
+ /// 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
+ /// ```
668
+ pub fn whole_chunks_mut < E > ( & mut self , chunk_size : E ) -> WholeChunksMut < A , D >
669
+ where E : IntoDimension < Dim =D > ,
670
+ S : DataMut
671
+ {
672
+ whole_chunks_mut_of ( self . view_mut ( ) , chunk_size)
673
+ }
674
+
631
675
// Return (length, stride) for diagonal
632
676
fn diag_params ( & self ) -> ( Ix , Ixs ) {
633
677
/* empty shape has len 1 */
0 commit comments