Mercurial > repos > public > sbplib_julia
comparison stencil.jl @ 69:8cd8d83b92e7
Add some notes to stencil
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 18 Jan 2019 10:12:23 +0100 |
parents | ef060ab3b035 |
children | 700a74c41b26 48079bd39969 |
comparison
equal
deleted
inserted
replaced
59:60d575e4a2d8 | 69:8cd8d83b92e7 |
---|---|
15 s = Stencil(range, s.weights[end:-1:1]) | 15 s = Stencil(range, s.weights[end:-1:1]) |
16 end | 16 end |
17 | 17 |
18 # Provides index into the Stencil based on offset for the root element | 18 # Provides index into the Stencil based on offset for the root element |
19 function Base.getindex(s::Stencil, i::Int) | 19 function Base.getindex(s::Stencil, i::Int) |
20 # TBD: Rearrange to mark with @boundscheck? | |
20 if s.range[1] <= i <= s.range[2] | 21 if s.range[1] <= i <= s.range[2] |
21 return s.weights[1 + i - s.range[1]] | 22 return s.weights[1 + i - s.range[1]] |
22 else | 23 else |
23 return 0 | 24 return 0 |
24 end | 25 end |
25 end | 26 end |
26 | 27 |
27 function apply(s::Stencil, v::AbstractVector, i::Int) | 28 function apply(s::Stencil, v::AbstractVector, i::Int) |
28 w = zero(eltype(v)) | 29 w = zero(eltype(v)) |
29 for j ∈ s.range[1]:s.range[2] | 30 for j ∈ s.range[1]:s.range[2] |
30 w += s[j]*v[i+j] | 31 w += s[j]*v[i+j] # TBD: Make this without boundschecks? |
31 end | 32 end |
32 return w | 33 return w |
33 end | 34 end |