Skip to content

Commit cf836c8

Browse files
committed
Rename subview_mut to index_axis_mut
1 parent a6867c3 commit cf836c8

File tree

4 files changed

+40
-27
lines changed

4 files changed

+40
-27
lines changed

examples/sort-axis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl<A, D> PermuteArray for Array<A, D>
109109
result = Array::from_shape_vec_unchecked(self.dim(), v);
110110
for i in 0..axis_len {
111111
let perm_i = perm.indices[i];
112-
Zip::from(result.subview_mut(axis, perm_i))
112+
Zip::from(result.index_axis_mut(axis, perm_i))
113113
.and(self.subview(axis, i))
114114
.apply(|to, from| {
115115
copy_nonoverlapping(from, to, 1)

src/impl_2d.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl<A, S> ArrayBase<S, Ix2>
2828
pub fn row_mut(&mut self, index: Ix) -> ArrayViewMut1<A>
2929
where S: DataMut
3030
{
31-
self.subview_mut(Axis(0), index)
31+
self.index_axis_mut(Axis(0), index)
3232
}
3333

3434
/// Return the number of rows (length of `Axis(0)`) in the two-dimensional array.
@@ -50,7 +50,7 @@ impl<A, S> ArrayBase<S, Ix2>
5050
pub fn column_mut(&mut self, index: Ix) -> ArrayViewMut1<A>
5151
where S: DataMut
5252
{
53-
self.subview_mut(Axis(1), index)
53+
self.index_axis_mut(Axis(1), index)
5454
}
5555

5656
/// Return the number of columns (length of `Axis(1)`) in the two-dimensional array.

src/impl_methods.rs

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,14 +521,14 @@ pub type Ixs = isize;
521521
///
522522
/// Subview methods allow you to restrict the array view while removing one
523523
/// axis from the array. Subview methods include [`.subview()`],
524-
/// [`.subview_mut()`], [`.into_subview()`], and [`.collapse_axis()`]. You
524+
/// [`.index_axis_mut()`], [`.into_subview()`], and [`.collapse_axis()`]. You
525525
/// can also take a subview by using a single index instead of a range when
526526
/// slicing.
527527
///
528528
/// Subview takes two arguments: `axis` and `index`.
529529
///
530530
/// [`.subview()`]: #method.subview
531-
/// [`.subview_mut()`]: #method.subview_mut
531+
/// [`.index_axis_mut()`]: #method.index_axis_mut
532532
/// [`.into_subview()`]: #method.into_subview
533533
/// [`.collapse_axis()`]: #method.collapse_axis
534534
///

0 commit comments

Comments
 (0)