Skip to content

Commit 9d197a3

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 While I'm not an expert at the unsafe coding guidelines for Rust, and there are more places in ndarray to revisit, I think it's best to change change 1 and 2 - they don't pass my internalized borrow checker. It seems as though the steps 1, 2, 3 could be against the rules 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 9d197a3

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();
2271+
let mut curr = self.raw_view_mut(); // mut borrow of the array here
2272+
let mut prev = curr.raw_view(); // derive further raw views from the same borrow
22722273
prev.slice_axis_inplace(axis, Slice::from(..-1));
2273-
let mut curr = self.raw_view_mut();
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)