Skip to content

Commit

Permalink
Refine PR #642 (#665)
Browse files Browse the repository at this point in the history
  • Loading branch information
jturner314 authored and LukeMathWalker committed Aug 4, 2019
1 parent 97d95b7 commit ce80d38
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/dimension/dynindeximpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<T: Copy + Zero> IxDynRepr<T> {
pub fn copy_from(x: &[T]) -> Self {
if x.len() <= CAP {
let mut arr = [T::zero(); CAP];
arr[..x.len()].clone_from_slice(&x[..]);
arr[..x.len()].copy_from_slice(&x[..]);
IxDynRepr::Inline(x.len() as _, arr)
} else {
Self::from(x)
Expand Down
11 changes: 4 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1538,14 +1538,11 @@ where
F: FnMut(&mut A),
{
if let Some(slc) = self.as_slice_memory_order_mut() {
// FIXME: Use for loop when slice iterator is perf is restored
for x in slc.iter_mut() {
f(x);
slc.iter_mut().for_each(f);
} else {
for row in self.inner_rows_mut() {
row.into_iter_().fold((), |(), elt| f(elt));
}
return;
}
for row in self.inner_rows_mut() {
row.into_iter_().fold((), |(), elt| f(elt));
}
}

Expand Down
14 changes: 4 additions & 10 deletions src/numeric_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

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

use crate::LinalgScalar;
Expand Down Expand Up @@ -51,12 +49,11 @@ where

// make it clear to the optimizer that this loop is short
// and can not be autovectorized.
// https://github.com/rust-ndarray/ndarray/pull/642#discussion_r296337112
for i in 0..xs.len() {
for (i, x) in xs.iter().enumerate() {
if i >= 7 {
break;
}
acc = f(acc.clone(), xs[i].clone())
acc = f(acc.clone(), x.clone())
}
acc
}
Expand Down Expand Up @@ -103,14 +100,11 @@ where
sum = sum + (p2 + p6);
sum = sum + (p3 + p7);

for i in 0..xs.len() {
for (i, (&x, &y)) in xs.iter().zip(ys).enumerate() {
if i >= 7 {
break;
}
unsafe {
// get_unchecked is needed to avoid the bounds check
sum = sum + xs[i] * *ys.get_unchecked(i);
}
sum = sum + x * y;
}
sum
}
Expand Down

0 comments on commit ce80d38

Please sign in to comment.