remove bounds check with iterators

This commit is contained in:
Magnus Ulimoen 2019-11-08 07:56:29 +01:00
parent 56688efcdf
commit a6bf554c60
1 changed files with 10 additions and 3 deletions

View File

@ -68,10 +68,17 @@ impl Upwind4 {
fut[i] += diff / dx;
}
for i in 4..nx - 4 {
let diff = diag.dot(&prev.slice(s!(i - 3..=i + 3)));
fut[(i)] += diff / dx;
for (window, f) in prev
.windows(diag.len())
.into_iter()
.skip(1)
.zip(fut.iter_mut().skip(4))
.take(nx - 8)
{
let diff = diag.dot(&window);
*f += diff / dx;
}
let last_elems = prev.slice(s!(nx - 7..));
for i in 0..4 {
let ii = nx - 4 + i;