Mercurial > repos > public > sbplib_julia
comparison src/SbpOperators/stencil.jl @ 1452:4f79ab676ebc bugfix/sbp_operators/stencil_return_type
Fix broken tests using sum(f,...). Needs to be evaluated for performance
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 24 Nov 2023 21:56:40 +0100 |
parents | 14cb97284373 |
children | 18cb103e499c |
comparison
equal
deleted
inserted
replaced
1446:d744b01be520 | 1452:4f79ab676ebc |
---|---|
67 end | 67 end |
68 return s.weights[1 + i - s.range[1]] | 68 return s.weights[1 + i - s.range[1]] |
69 end | 69 end |
70 | 70 |
71 Base.@propagate_inbounds @inline function apply_stencil(s::Stencil, v::AbstractVector, i::Int) | 71 Base.@propagate_inbounds @inline function apply_stencil(s::Stencil, v::AbstractVector, i::Int) |
72 w = zero(promote_type(eltype(s),eltype(v))) | 72 return sum(1:length(s)) do k |
73 @simd for k ∈ 1:length(s) | 73 s.weights[k]*v[i + s.range[k]] |
74 w += s.weights[k]*v[i + s.range[k]] | |
75 end | 74 end |
76 | |
77 return w | |
78 end | 75 end |
79 | 76 |
80 Base.@propagate_inbounds @inline function apply_stencil_backwards(s::Stencil, v::AbstractVector, i::Int) | 77 Base.@propagate_inbounds @inline function apply_stencil_backwards(s::Stencil, v::AbstractVector, i::Int) |
81 w = zero(promote_type(eltype(s),eltype(v))) | 78 return sum(length(s):-1:1) do k |
82 @simd for k ∈ length(s):-1:1 | 79 s.weights[k]*v[i - s.range[k]] |
83 w += s.weights[k]*v[i - s.range[k]] | |
84 end | 80 end |
85 return w | |
86 end | 81 end |
87 | 82 |
88 function left_pad(s::Stencil, N) | 83 function left_pad(s::Stencil, N) |
89 weights = LazyTensors.left_pad_tuple(s.weights, zero(eltype(s)), N) | 84 weights = LazyTensors.left_pad_tuple(s.weights, zero(eltype(s)), N) |
90 range = (first(s.range) - (N - length(s.weights))):last(s.range) | 85 range = (first(s.range) - (N - length(s.weights))):last(s.range) |