Skip to content

Commit

Permalink
Tweak how we create raw views in accumulate_axis_inplace
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bluss committed Sep 11, 2019
1 parent bcd7078 commit 7b87d5a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/impl_methods.rs
Expand Up @@ -2268,9 +2268,9 @@ where
if self.len_of(axis) <= 1 {
return;
}
let mut prev = self.raw_view();
prev.slice_axis_inplace(axis, Slice::from(..-1));
let mut curr = self.raw_view_mut();
let mut prev = curr.clone().into_raw_view();
prev.slice_axis_inplace(axis, Slice::from(..-1));
curr.slice_axis_inplace(axis, Slice::from(1..));
// This implementation relies on `Zip` iterating along `axis` in order.
Zip::from(prev).and(curr).apply(|prev, curr| unsafe {
Expand Down

0 comments on commit 7b87d5a

Please sign in to comment.