Skip to content

Commit a6867c3

Browse files
committed
Rename subview_inplace to collapse_axis
1 parent 245cfbb commit a6867c3

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

src/impl_methods.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
310310
where
311311
Do: Dimension,
312312
{
313-
// Slice and subview in-place without changing the number of dimensions.
313+
// Slice and collapse in-place without changing the number of dimensions.
314314
self.slice_inplace(&*info);
315315

316316
let indices: &[SliceOrIndex] = (**info).as_ref();
@@ -364,7 +364,7 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
364364
}
365365
&SliceOrIndex::Index(index) => {
366366
let i_usize = abs_index(self.len_of(Axis(axis)), index);
367-
self.subview_inplace(Axis(axis), i_usize)
367+
self.collapse_axis(Axis(axis), i_usize)
368368
}
369369
});
370370
}
@@ -542,6 +542,15 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
542542
}
543543
}
544544

545+
/// Collapse the axis into length one, selecting the subview at the given
546+
/// `index` along the axis.
547+
///
548+
/// **Panics** if `index` is past the length of the axis.
549+
pub fn collapse_axis(&mut self, axis: Axis, index: usize) {
550+
dimension::do_sub(&mut self.dim, &mut self.ptr, &self.strides,
551+
axis.index(), index)
552+
}
553+
545554
/// Along `axis`, select the subview `index` and return a
546555
/// view with that axis removed.
547556
///
@@ -605,9 +614,9 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
605614
/// and select the subview of `index` along that axis.
606615
///
607616
/// **Panics** if `index` is past the length of the axis.
617+
#[deprecated(note="renamed to `collapse_axis`", since="0.12.1")]
608618
pub fn subview_inplace(&mut self, axis: Axis, index: Ix) {
609-
dimension::do_sub(&mut self.dim, &mut self.ptr, &self.strides,
610-
axis.index(), index)
619+
self.collapse_axis(axis, index)
611620
}
612621

613622
/// Along `axis`, select the subview `index` and return `self`
@@ -617,7 +626,7 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
617626
pub fn into_subview(mut self, axis: Axis, index: Ix) -> ArrayBase<S, D::Smaller>
618627
where D: RemoveAxis,
619628
{
620-
self.subview_inplace(axis, index);
629+
self.collapse_axis(axis, index);
621630
self.remove_axis(axis)
622631
}
623632

@@ -648,7 +657,7 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
648657
{
649658
let mut subs = vec![self.view(); indices.len()];
650659
for (&i, sub) in zip(indices, &mut subs[..]) {
651-
sub.subview_inplace(axis, i);
660+
sub.collapse_axis(axis, i);
652661
}
653662
if subs.is_empty() {
654663
let mut dim = self.raw_dim();

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ pub type Ixs = isize;
455455
/// If a range is used, the axis is preserved. If an index is used, a subview
456456
/// is taken with respect to the axis. See [*Subviews*](#subviews) for more
457457
/// information about subviews. Note that [`.slice_inplace()`] behaves like
458-
/// [`.subview_inplace()`] by preserving the number of dimensions.
458+
/// [`.collapse_axis()`] by preserving the number of dimensions.
459459
///
460460
/// [`.slice()`]: #method.slice
461461
/// [`.slice_mut()`]: #method.slice_mut
@@ -521,7 +521,7 @@ 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 [`.subview_inplace()`]. You
524+
/// [`.subview_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
///
@@ -530,7 +530,7 @@ pub type Ixs = isize;
530530
/// [`.subview()`]: #method.subview
531531
/// [`.subview_mut()`]: #method.subview_mut
532532
/// [`.into_subview()`]: #method.into_subview
533-
/// [`.subview_inplace()`]: #method.subview_inplace
533+
/// [`.collapse_axis()`]: #method.collapse_axis
534534
///
535535
/// ```
536536
/// #[macro_use(s)] extern crate ndarray;
@@ -574,7 +574,7 @@ pub type Ixs = isize;
574574
/// # }
575575
/// ```
576576
///
577-
/// [`.subview_inplace()`] modifies the view in the same way as [`.subview()`],
577+
/// [`.collapse_axis()`] modifies the view in the same way as [`.subview()`],
578578
/// but since it is *in place*, it cannot remove the collapsed axis. It becomes
579579
/// an axis of length 1.
580580
///

tests/array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ fn test_slice_with_subview() {
276276
}
277277

278278
#[test]
279-
fn test_slice_inplace_with_subview_inplace() {
279+
fn test_slice_inplace_with_indices() {
280280
let mut arr = RcArray::<usize, _>::zeros((3, 5, 4));
281281
for (i, elt) in arr.iter_mut().enumerate() {
282282
*elt = i;

0 commit comments

Comments
 (0)