@@ -2444,6 +2444,35 @@ where
24442444 }
24452445 }
24462446
2447+ /// Remove each `index`th element along `axis` and shift down elements from higher indexes.
2448+ ///
2449+ /// Decreases the length of `axis` by one.
2450+ ///
2451+ /// ***Panics** if `axis` or `index` is out of bounds.
2452+ pub fn shift_remove_index ( & mut self , axis : Axis , index : usize )
2453+ where
2454+ S : DataOwned + DataMut ,
2455+ {
2456+ // TODO: It's possible to choose to shift the elment to the front or the back here,
2457+ // whichever is closer.
2458+ let ( _, mut tail) = self . view_mut ( ) . split_at ( axis, index) ;
2459+ // shift elements to the back
2460+ // use swap to keep all elements initialized (as required by owned storage)
2461+ if tail. len_of ( axis) > 1 {
2462+ Zip :: from ( tail. lanes_mut ( axis) ) . for_each ( |lane| {
2463+ // TODO give ArrayViewMut1 a split_first method?
2464+ let ( mut fst, mut rest) = lane. split_at ( Axis ( 0 ) , 1 ) ;
2465+ let mut dst = & mut fst[ 0 ] ;
2466+ for elt in rest. iter_mut ( ) {
2467+ std:: mem:: swap ( dst, elt) ;
2468+ dst = elt;
2469+ }
2470+ } ) ;
2471+ }
2472+ // then slice the axis in place to cut out the removed final element
2473+ self . slice_axis_inplace ( axis, Slice :: new ( 0 , Some ( -1 ) , 1 ) ) ;
2474+ }
2475+
24472476 /// Iterates over pairs of consecutive elements along the axis.
24482477 ///
24492478 /// The first argument to the closure is an element, and the second
0 commit comments