Skip to content

Commit a4ab61d

Browse files
committed
Rename into_subview to index_axis_move
1 parent cf836c8 commit a4ab61d

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

src/impl_methods.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,19 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
571571
S: DataMut,
572572
D: RemoveAxis,
573573
{
574-
self.view_mut().into_subview(axis, index)
574+
self.view_mut().index_axis_move(axis, index)
575+
}
576+
577+
/// Along `axis`, select the subview `index` and return `self`
578+
/// with that axis removed.
579+
///
580+
/// See [`.subview()`](#method.subview) and [*Subviews*](#subviews) for full documentation.
581+
pub fn index_axis_move(mut self, axis: Axis, index: usize) -> ArrayBase<S, D::Smaller>
582+
where
583+
D: RemoveAxis,
584+
{
585+
self.collapse_axis(axis, index);
586+
self.remove_axis(axis)
575587
}
576588

577589
/// Collapse the axis into length one, selecting the subview at the given
@@ -607,7 +619,7 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
607619
pub fn subview(&self, axis: Axis, index: Ix) -> ArrayView<A, D::Smaller>
608620
where D: RemoveAxis,
609621
{
610-
self.view().into_subview(axis, index)
622+
self.view().index_axis_move(axis, index)
611623
}
612624

613625
/// Along `axis`, select the subview `index` and return a read-write view
@@ -634,13 +646,11 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
634646

635647
/// Along `axis`, select the subview `index` and return `self`
636648
/// with that axis removed.
637-
///
638-
/// See [`.subview()`](#method.subview) and [*Subviews*](#subviews) for full documentation.
639-
pub fn into_subview(mut self, axis: Axis, index: Ix) -> ArrayBase<S, D::Smaller>
649+
#[deprecated(note="renamed to `index_axis_move`", since="0.12.1")]
650+
pub fn into_subview(self, axis: Axis, index: Ix) -> ArrayBase<S, D::Smaller>
640651
where D: RemoveAxis,
641652
{
642-
self.collapse_axis(axis, index);
643-
self.remove_axis(axis)
653+
self.index_axis_move(axis, index)
644654
}
645655

646656
/// Along `axis`, select arbitrary subviews corresponding to `indices`

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,15 +521,15 @@ 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-
/// [`.index_axis_mut()`], [`.into_subview()`], and [`.collapse_axis()`]. You
524+
/// [`.index_axis_mut()`], [`.index_axis_move()`], 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
531531
/// [`.index_axis_mut()`]: #method.index_axis_mut
532-
/// [`.into_subview()`]: #method.into_subview
532+
/// [`.index_axis_move()`]: #method.index_axis_move
533533
/// [`.collapse_axis()`]: #method.collapse_axis
534534
///
535535
/// ```

tests/array.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ fn swapaxes()
590590
#[test]
591591
fn permuted_axes()
592592
{
593-
let a = array![1].into_subview(Axis(0), 0);
593+
let a = array![1].index_axis_move(Axis(0), 0);
594594
let permuted = a.view().permuted_axes([]);
595595
assert_eq!(a, permuted);
596596

@@ -932,14 +932,14 @@ fn as_slice_memory_order()
932932
fn array0_into_scalar() {
933933
// With this kind of setup, the `Array`'s pointer is not the same as the
934934
// underlying `Vec`'s pointer.
935-
let a: Array0<i32> = array![4, 5, 6, 7].into_subview(Axis(0), 2);
935+
let a: Array0<i32> = array![4, 5, 6, 7].index_axis_move(Axis(0), 2);
936936
assert_ne!(a.as_ptr(), a.into_raw_vec().as_ptr());
937937
// `.into_scalar()` should still work correctly.
938-
let a: Array0<i32> = array![4, 5, 6, 7].into_subview(Axis(0), 2);
938+
let a: Array0<i32> = array![4, 5, 6, 7].index_axis_move(Axis(0), 2);
939939
assert_eq!(a.into_scalar(), 6);
940940

941941
// It should work for zero-size elements too.
942-
let a: Array0<()> = array![(), (), (), ()].into_subview(Axis(0), 2);
942+
let a: Array0<()> = array![(), (), (), ()].index_axis_move(Axis(0), 2);
943943
assert_eq!(a.into_scalar(), ());
944944
}
945945

tests/dimension.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn remove_axis()
5656
a.subview(Axis(1), 0);
5757

5858
let a = RcArray::<f32, _>::zeros(vec![4,5,6]);
59-
let _b = a.into_subview(Axis(1), 0).reshape((4, 6)).reshape(vec![2, 3, 4]);
59+
let _b = a.index_axis_move(Axis(1), 0).reshape((4, 6)).reshape(vec![2, 3, 4]);
6060
}
6161

6262
#[test]

0 commit comments

Comments
 (0)