Skip to content

Commit 7b87d5a

Browse files
committed
Tweak how we create raw views in accumulate_axis_inplace
We had: 1. let ptr1 = self.raw_view(); // Borrow &self 2. let ptr2 = self.raw_view_mut(); // Borrow &mut self 3. Use ptr1 and ptr2 I'm not an expert - we'll need to study and learn more, and the unsafe rust guidelines are not finished. And this is like the first place and far from the last, where we need to revisit unsafe code in ndarray, for updated rules. It seems as though the steps 1, 2, 3 could be wrong as ptr1 is borrowed from the array data, and its scope straddles the mut borrow of the array data in 2. For this reason, I think this would be better: 1. let ptr2 = self.raw_view_mut() // Borrow &mut self 2. let ptr1 = derive from ptr2 3. use ptr1 and ptr2 RawView should hopefully be our ally in making a better ndarray from the foundation.
1 parent bcd7078 commit 7b87d5a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/impl_methods.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,9 +2268,9 @@ where
22682268
if self.len_of(axis) <= 1 {
22692269
return;
22702270
}
2271-
let mut prev = self.raw_view();
2272-
prev.slice_axis_inplace(axis, Slice::from(..-1));
22732271
let mut curr = self.raw_view_mut();
2272+
let mut prev = curr.clone().into_raw_view();
2273+
prev.slice_axis_inplace(axis, Slice::from(..-1));
22742274
curr.slice_axis_inplace(axis, Slice::from(1..));
22752275
// This implementation relies on `Zip` iterating along `axis` in order.
22762276
Zip::from(prev).and(curr).apply(|prev, curr| unsafe {

0 commit comments

Comments
 (0)