diff stencil.jl @ 122:6c6979ff17f4 cell_based_test

Introduce and use apply_backwards for stencils
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 12 Feb 2019 15:18:18 +0100
parents 8d505e9bc715
children 7c0b9bb7ab4d
line wrap: on
line diff
--- a/stencil.jl	Sun Feb 10 19:16:14 2019 +0100
+++ b/stencil.jl	Tue Feb 12 15:18:18 2019 +0100
@@ -25,3 +25,12 @@
     end
     return w
 end
+
+Base.@propagate_inbounds function apply_backwards(s::Stencil, v::AbstractVector, i::Int)
+    w = zero(eltype(v))
+    for j ∈ s.range[2]:-1:s.range[1]
+        @inbounds weight = s[j]
+        w += weight*v[i-j]
+    end
+    return w
+end