comparison 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
comparison
equal deleted inserted replaced
77:2be36b38389d 84:48079bd39969
1 struct Stencil 1 struct Stencil{T<:Real,N}
2 range::NTuple{2,Int} 2 range::Tuple{Int,Int}
3 weights::Vector # TBD: Should this be a tuple? 3 weights::NTuple{N,T}
4 function Stencil(range, weights)
5 width = range[2]-range[1]+1
6 if width != length(weights)
7 error("The width and the number of weights must be the same")
8 end
9 new(range, weights)
10 end
11 end 4 end
12 5
13 function flip(s::Stencil) 6 function flip(s::Stencil)
14 range = (-s.range[2], -s.range[1]) 7 range = (-s.range[2], -s.range[1])
15 s = Stencil(range, s.weights[end:-1:1]) 8 return Stencil(range, reverse(s.weights))
16 end 9 end
17 10
18 # Provides index into the Stencil based on offset for the root element 11 # Provides index into the Stencil based on offset for the root element
19 function Base.getindex(s::Stencil, i::Int) 12 function Base.getindex(s::Stencil, i::Int)
20 # TBD: Rearrange to mark with @boundscheck? 13 # TBD: Rearrange to mark with @boundscheck?