changeset 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 015bd5f33a54
children 7f72e7e14659
files diffOp.jl sbpD2.jl stencil.jl
diffstat 3 files changed, 9 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/diffOp.jl	Thu Jan 24 14:27:57 2019 +0100
+++ b/diffOp.jl	Thu Jan 24 14:33:49 2019 +0100
@@ -33,8 +33,8 @@
 end
 
 # Differential operator for a*d^2/dx^2
-struct Laplace{D, T<:Real} <: DiffOp
-    grid::Grid.EquidistantGrid{D,T}
+struct Laplace{Dim, T<:Real} <: DiffOp
+    grid::Grid.EquidistantGrid{Dim,T}
     a::T
     op::D2{Float64}
 end
--- a/sbpD2.jl	Thu Jan 24 14:27:57 2019 +0100
+++ b/sbpD2.jl	Thu Jan 24 14:33:49 2019 +0100
@@ -28,8 +28,8 @@
 
 struct D2{T} <: ConstantStencilOperator
     quadratureClosure::Vector{T}
-    innerStencil::Stencil
-    closureStencils::Vector{Stencil} # TBD: Should this be a tuple?
+    innerStencil::Stencil{T}
+    closureStencils::Vector{Stencil{T}} # TBD: Should this be a tuple?
     eClosure::Vector{T}
     dClosure::Vector{T}
     parity::Parity
@@ -52,7 +52,7 @@
 
     # Create boundary stencils
     boundarySize = length(d["boundary_stencils"])
-    closureStencils = Vector{Stencil}()
+    closureStencils = Vector{typeof(innerStencil)}()
 
     for i ∈ 1:boundarySize
         stencilWeights = stringToVector(Float64, d["boundary_stencils"][i])
--- 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