comparison stencil.jl @ 87:38733e84ef1a patch_based_test

Clean up bounds checking in stencil. change to using uview in DiffOp
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Fri, 25 Jan 2019 13:40:15 +0100
parents 7f72e7e14659
children 170e5447bc19
comparison
equal deleted inserted replaced
86:34fd86e9d0b9 87:38733e84ef1a
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 @boundscheck if i < s.range[1] || s.range[2] < i
21 if s.range[1] <= i <= s.range[2]
22 return s.weights[1 + i - s.range[1]]
23 else
24 return eltype(s.weights)(0) 21 return eltype(s.weights)(0)
25 end 22 end
23 return s.weights[1 + i - s.range[1]]
26 end 24 end
27 25
28 @inline function apply(s::Stencil, v::AbstractVector, i::Int) 26 Base.@propagate_inbounds function apply(s::Stencil, v::AbstractVector, i::Int)
29 w = zero(eltype(v)) 27 w = zero(eltype(v))
30 for j ∈ s.range[1]:s.range[2] 28 for j ∈ s.range[1]:s.range[2]
31 @inbounds w += s[j]*v[i+j] # TBD: Make this without boundschecks? 29 @inbounds weight = s[j]
30 w += weight*v[i+j]
32 end 31 end
33 return w 32 return w
34 end 33 end