Mercurial > repos > public > sbplib_julia
comparison stencil.jl @ 89:c0729ade65da patch_based_test
Merge with default
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Fri, 25 Jan 2019 16:47:51 +0100 |
parents | 170e5447bc19 48079bd39969 |
children |
comparison
equal
deleted
inserted
replaced
88:170e5447bc19 | 89:c0729ade65da |
---|---|
1 struct Stencil{T<:Real} | 1 struct Stencil{T<:Real,N} |
2 range::NTuple{2,Int} | 2 range::Tuple{Int,Int} |
3 weights::Vector{T} # 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{eltype(weights)}(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 @boundscheck if i < s.range[1] || s.range[2] < i | 13 @boundscheck if i < s.range[1] || s.range[2] < i |