@@ -542,6 +542,38 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
542542 }
543543 }
544544
545+ /// Along `axis`, select the subview `index` and return a read-write view
546+ /// with the axis removed.
547+ ///
548+ /// **Panics** if `axis` or `index` is out of bounds.
549+ ///
550+ /// ```
551+ /// use ndarray::{arr2, aview2, Axis};
552+ ///
553+ /// let mut a = arr2(&[[1., 2. ],
554+ /// [3., 4. ]]);
555+ /// // . \
556+ /// // . axis 1, column 1
557+ /// // axis 1, column 0
558+ ///
559+ /// {
560+ /// let mut column1 = a.index_axis_mut(Axis(1), 1);
561+ /// column1 += 10.;
562+ /// }
563+ ///
564+ /// assert!(
565+ /// a == aview2(&[[1., 12.],
566+ /// [3., 14.]])
567+ /// );
568+ /// ```
569+ pub fn index_axis_mut ( & mut self , axis : Axis , index : usize ) -> ArrayViewMut < A , D :: Smaller >
570+ where
571+ S : DataMut ,
572+ D : RemoveAxis ,
573+ {
574+ self . view_mut ( ) . into_subview ( axis, index)
575+ }
576+
545577 /// Collapse the axis into length one, selecting the subview at the given
546578 /// `index` along the axis.
547579 ///
@@ -582,32 +614,13 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
582614 /// with the axis removed.
583615 ///
584616 /// **Panics** if `axis` or `index` is out of bounds.
585- ///
586- /// ```
587- /// use ndarray::{arr2, aview2, Axis};
588- ///
589- /// let mut a = arr2(&[[1., 2. ],
590- /// [3., 4. ]]);
591- /// // . \
592- /// // . axis 1, column 1
593- /// // axis 1, column 0
594- ///
595- /// {
596- /// let mut column1 = a.subview_mut(Axis(1), 1);
597- /// column1 += 10.;
598- /// }
599- ///
600- /// assert!(
601- /// a == aview2(&[[1., 12.],
602- /// [3., 14.]])
603- /// );
604- /// ```
617+ #[ deprecated( note="renamed to `index_axis_mut`" , since="0.12.1" ) ]
605618 pub fn subview_mut ( & mut self , axis : Axis , index : Ix )
606619 -> ArrayViewMut < A , D :: Smaller >
607620 where S : DataMut ,
608621 D : RemoveAxis ,
609622 {
610- self . view_mut ( ) . into_subview ( axis, index)
623+ self . index_axis_mut ( axis, index)
611624 }
612625
613626 /// Collapse dimension `axis` into length one,
@@ -1894,7 +1907,7 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
18941907 let view_stride = self . strides . axis ( axis) ;
18951908 // use the 0th subview as a map to each 1d array view extended from
18961909 // the 0th element.
1897- self . subview_mut ( axis, 0 ) . map_mut ( |first_elt : & mut A | {
1910+ self . index_axis_mut ( axis, 0 ) . map_mut ( |first_elt : & mut A | {
18981911 unsafe {
18991912 mapping ( ArrayViewMut :: new_ ( first_elt, Ix1 ( view_len) , Ix1 ( view_stride) ) )
19001913 }
0 commit comments