Mercurial > repos > public > sbplib_julia
changeset 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 | e4fa13137d12 |
children | 4640839b1616 |
files | stencil.jl |
diffstat | 1 files changed, 6 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/stencil.jl Fri Jan 18 13:51:32 2019 +0100 +++ b/stencil.jl Fri Jan 18 14:21:58 2019 +0100 @@ -18,17 +18,18 @@ # Provides index into the Stencil based on offset for the root element function Base.getindex(s::Stencil, i::Int) - if s.range[1] <= i <= s.range[2] - return s.weights[1 + i - s.range[1]] - else + @boundscheck if i < s.range[1] || s.range[2] < i return eltype(s.weights)(0) end + + return s.weights[1 + i - s.range[1]] end -function apply(s::Stencil, v::AbstractVector, i::Int) +Base.@propagate_inbounds function apply(s::Stencil, v::AbstractVector, i::Int) w = zero(eltype(v)) for j ∈ s.range[1]:s.range[2] - w += s[j]*v[i+j] + @inbounds weight = s[j] + w += weight*v[i+j] end return w end