Skip to content

Refine PR #642 #665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1557,14 +1557,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