Skip to content

Commit 198e8b8

Browse files
committed
Refine PR rust-ndarray#642
1 parent 2075267 commit 198e8b8

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

src/dimension/dynindeximpl.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,14 +1557,11 @@ where
15571557
F: FnMut(&mut A),
15581558
{
15591559
if let Some(slc) = self.as_slice_memory_order_mut() {
1560-
// FIXME: Use for loop when slice iterator is perf is restored
1561-
for x in slc.iter_mut() {
1562-
f(x);
1560+
slc.iter_mut().for_each(f);
1561+
} else {
1562+
for row in self.inner_rows_mut() {
1563+
row.into_iter_().fold((), |(), elt| f(elt));
15631564
}
1564-
return;
1565-
}
1566-
for row in self.inner_rows_mut() {
1567-
row.into_iter_().fold((), |(), elt| f(elt));
15681565
}
15691566
}
15701567

src/numeric_util.rs

Lines changed: 4 additions & 10 deletions
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)