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; fut[i] += diff / dx;
} }
for i in 4..nx - 4 { for (window, f) in prev
let diff = diag.dot(&prev.slice(s!(i - 3..=i + 3))); .windows(diag.len())
fut[(i)] += diff / dx; .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..)); let last_elems = prev.slice(s!(nx - 7..));
for i in 0..4 { for i in 0..4 {
let ii = nx - 4 + i; let ii = nx - 4 + i;