diff stencil.jl @ 80:700a74c41b26 patch_based_test

Improve type stability
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Thu, 24 Jan 2019 14:33:49 +0100
parents 8cd8d83b92e7
children 7f72e7e14659
line wrap: on
line diff
--- a/stencil.jl	Thu Jan 24 14:27:57 2019 +0100
+++ b/stencil.jl	Thu Jan 24 14:33:49 2019 +0100
@@ -1,12 +1,12 @@
-struct Stencil
+struct Stencil{T<:Real}
     range::NTuple{2,Int}
-    weights::Vector # TBD: Should this be a tuple?
+    weights::Vector{T} # 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)
+        new{eltype(weights)}(range, weights)
     end
 end
 
@@ -21,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