Skip to content

Commit a188497

Browse files
committed
simplify split_at pointer offseting
1 parent e0527a7 commit a188497

File tree

1 file changed

+4
-22
lines changed

1 file changed

+4
-22
lines changed

src/lib.rs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ pub use dimension::{
9494
RemoveAxis,
9595
};
9696

97+
use dimension::stride_offset;
98+
9799
pub use dimension::NdIndex;
98100
pub use indexes::Indexes;
99101
pub use shape_error::ShapeError;
@@ -936,17 +938,7 @@ impl<'a, A, D> ArrayView<'a, A, D>
936938
let right_ptr = if index == self.shape()[axis] {
937939
self.ptr
938940
} else {
939-
let mut indices = self.dim.clone();
940-
for (ax, ind) in indices.slice_mut().iter_mut().enumerate() {
941-
if ax != axis {
942-
*ind = 0;
943-
}
944-
else {
945-
*ind = index;
946-
}
947-
}
948-
let offset = self.dim.stride_offset_checked(&self.strides,
949-
&indices).unwrap();
941+
let offset = stride_offset(index, self.strides.slice()[axis]);
950942
unsafe {
951943
self.ptr.offset(offset)
952944
}
@@ -1076,17 +1068,7 @@ impl<'a, A, D> ArrayViewMut<'a, A, D>
10761068
self.ptr
10771069
}
10781070
else {
1079-
let mut indices = self.dim.clone();
1080-
for (ax, ind) in indices.slice_mut().iter_mut().enumerate() {
1081-
if ax != axis {
1082-
*ind = 0;
1083-
}
1084-
else {
1085-
*ind = index;
1086-
}
1087-
}
1088-
let offset = self.dim.stride_offset_checked(&self.strides,
1089-
&indices).unwrap();
1071+
let offset = stride_offset(index, self.strides.slice()[axis]);
10901072
unsafe {
10911073
self.ptr.offset(offset)
10921074
}

0 commit comments

Comments
 (0)