diff stencil.jl @ 84:48079bd39969

Change to using tuples in stencils and ops
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 25 Jan 2019 15:20:40 +0100
parents 8cd8d83b92e7
children 8d505e9bc715 c0729ade65da
line wrap: on
line diff
--- a/stencil.jl	Thu Jan 24 13:33:07 2019 +0100
+++ b/stencil.jl	Fri Jan 25 15:20:40 2019 +0100
@@ -1,18 +1,11 @@
-struct Stencil
-    range::NTuple{2,Int}
-    weights::Vector # TBD: Should this be a tuple?
-    function Stencil(range, weights)
-        width = range[2]-range[1]+1
-        if width != length(weights)
-            error("The width and the number of weights must be the same")
-        end
-        new(range, weights)
-    end
+struct Stencil{T<:Real,N}
+    range::Tuple{Int,Int}
+    weights::NTuple{N,T}
 end
 
 function flip(s::Stencil)
     range = (-s.range[2], -s.range[1])
-    s = Stencil(range, s.weights[end:-1:1])
+    return Stencil(range, reverse(s.weights))
 end
 
 # Provides index into the Stencil based on offset for the root element