changeset 67:7fd4e7a1cd38 cell_based_test

Make stencil more type stabeler
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 17 Jan 2019 15:52:25 +0100
parents 543b7a5ab831
children d485da6e3a77
files stencil.jl
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/stencil.jl	Thu Jan 17 15:32:53 2019 +0100
+++ b/stencil.jl	Thu Jan 17 15:52:25 2019 +0100
@@ -1,12 +1,13 @@
-struct Stencil
+struct Stencil{T<:Real}
     range::NTuple{2,Int}
-    weights::Vector # TBD: Should this be a tuple?
+    weights::Vector{T} # Should this be a tuple?? (Check type stability)
+
     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)
+        new{eltype(weights)}(range, weights)
     end
 end
 
@@ -20,7 +21,7 @@
     if s.range[1] <= i <= s.range[2]
         return s.weights[1 + i - s.range[1]]
     else
-        return 0
+        return eltype(s.weights)(0)
     end
 end