Skip to content
Closed
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
12 changes: 4 additions & 8 deletions src/numeric_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// 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 +48,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,13 +99,13 @@ where
sum = sum + (p2 + p6);
sum = sum + (p3 + p7);

for i in 0..xs.len() {
for (i, x) in xs.iter().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 * *ys.get_unchecked(i);
}
}
sum
Expand Down