From 7b87d5ab7e0d3fe3ad770a74c405ee28bbe8ce52 Mon Sep 17 00:00:00 2001 From: bluss Date: Wed, 11 Sep 2019 20:44:26 +0200 Subject: [PATCH] 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. --- src/impl_methods.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/impl_methods.rs b/src/impl_methods.rs index 8e11fab3f..e65d8fc93 100644 --- a/src/impl_methods.rs +++ b/src/impl_methods.rs @@ -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 {