Mercurial > repos > public > sbplib_julia
comparison stencil.jl @ 71:18d0d794d3bb cell_based_test
Make stencils respond to @ inbounds
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 18 Jan 2019 14:21:58 +0100 |
parents | 7fd4e7a1cd38 |
children | b795ec7f9ca0 |
comparison
equal
deleted
inserted
replaced
70:e4fa13137d12 | 71:18d0d794d3bb |
---|---|
16 s = Stencil(range, s.weights[end:-1:1]) | 16 s = Stencil(range, s.weights[end:-1:1]) |
17 end | 17 end |
18 | 18 |
19 # Provides index into the Stencil based on offset for the root element | 19 # Provides index into the Stencil based on offset for the root element |
20 function Base.getindex(s::Stencil, i::Int) | 20 function Base.getindex(s::Stencil, i::Int) |
21 if s.range[1] <= i <= s.range[2] | 21 @boundscheck if i < s.range[1] || s.range[2] < i |
22 return s.weights[1 + i - s.range[1]] | |
23 else | |
24 return eltype(s.weights)(0) | 22 return eltype(s.weights)(0) |
25 end | 23 end |
24 | |
25 return s.weights[1 + i - s.range[1]] | |
26 end | 26 end |
27 | 27 |
28 function apply(s::Stencil, v::AbstractVector, i::Int) | 28 Base.@propagate_inbounds function apply(s::Stencil, v::AbstractVector, i::Int) |
29 w = zero(eltype(v)) | 29 w = zero(eltype(v)) |
30 for j ∈ s.range[1]:s.range[2] | 30 for j ∈ s.range[1]:s.range[2] |
31 w += s[j]*v[i+j] | 31 @inbounds weight = s[j] |
32 w += weight*v[i+j] | |
32 end | 33 end |
33 return w | 34 return w |
34 end | 35 end |