Skip to content

Commit ce80d38

Browse files
jturner314LukeMathWalker
authored andcommitted
Refine PR #642 (#665)
1 parent 97d95b7 commit ce80d38

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

src/dimension/dynindeximpl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<T: Copy + Zero> IxDynRepr<T> {
4949
pub fn copy_from(x: &[T]) -> Self {
5050
if x.len() <= CAP {
5151
let mut arr = [T::zero(); CAP];
52-
arr[..x.len()].clone_from_slice(&x[..]);
52+
arr[..x.len()].copy_from_slice(&x[..]);
5353
IxDynRepr::Inline(x.len() as _, arr)
5454
} else {
5555
Self::from(x)

src/lib.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -1538,14 +1538,11 @@ where
15381538
F: FnMut(&mut A),
15391539
{
15401540
if let Some(slc) = self.as_slice_memory_order_mut() {
1541-
// FIXME: Use for loop when slice iterator is perf is restored
1542-
for x in slc.iter_mut() {
1543-
f(x);
1541+
slc.iter_mut().for_each(f);
1542+
} else {
1543+
for row in self.inner_rows_mut() {
1544+
row.into_iter_().fold((), |(), elt| f(elt));
15441545
}
1545-
return;
1546-
}
1547-
for row in self.inner_rows_mut() {
1548-
row.into_iter_().fold((), |(), elt| f(elt));
15491546
}
15501547
}
15511548

src/numeric_util.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
// https://github.com/rust-ndarray/ndarray/pull/642#discussion_r296074711
10-
#![allow(clippy::needless_range_loop)]
119
use std::cmp;
1210

1311
use crate::LinalgScalar;
@@ -51,12 +49,11 @@ where
5149

5250
// make it clear to the optimizer that this loop is short
5351
// and can not be autovectorized.
54-
// https://github.com/rust-ndarray/ndarray/pull/642#discussion_r296337112
55-
for i in 0..xs.len() {
52+
for (i, x) in xs.iter().enumerate() {
5653
if i >= 7 {
5754
break;
5855
}
59-
acc = f(acc.clone(), xs[i].clone())
56+
acc = f(acc.clone(), x.clone())
6057
}
6158
acc
6259
}
@@ -103,14 +100,11 @@ where
103100
sum = sum + (p2 + p6);
104101
sum = sum + (p3 + p7);
105102

106-
for i in 0..xs.len() {
103+
for (i, (&x, &y)) in xs.iter().zip(ys).enumerate() {
107104
if i >= 7 {
108105
break;
109106
}
110-
unsafe {
111-
// get_unchecked is needed to avoid the bounds check
112-
sum = sum + xs[i] * *ys.get_unchecked(i);
113-
}
107+
sum = sum + x * y;
114108
}
115109
sum
116110
}

0 commit comments

Comments
 (0)