Mercurial > repos > public > sbplib_julia
changeset 1063:f98893154e22 feature/nested_stencils
Fix type instability for stencil application when weights and vector didn't match
(grafted from a7f898b1ce1ea3adfe21201d3ccafdffb09c5be6)
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 14 Feb 2022 14:28:48 +0100 |
parents | a76830879c63 |
children | a601427023e3 |
files | src/SbpOperators/stencil.jl test/SbpOperators/stencil_test.jl |
diffstat | 2 files changed, 13 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/SbpOperators/stencil.jl Sun Feb 13 22:00:02 2022 +0100 +++ b/src/SbpOperators/stencil.jl Mon Feb 14 14:28:48 2022 +0100 @@ -69,7 +69,7 @@ end Base.@propagate_inbounds @inline function apply_stencil(s::Stencil, v::AbstractVector, i::Int) - w = zero(eltype(v)) + w = zero(promote_type(eltype(s),eltype(v))) @simd for k ∈ 1:length(s) w += s.weights[k]*v[i + s.range[k]] end
--- a/test/SbpOperators/stencil_test.jl Sun Feb 13 22:00:02 2022 +0100 +++ b/test/SbpOperators/stencil_test.jl Mon Feb 14 14:28:48 2022 +0100 @@ -43,6 +43,18 @@ @testset "promotion" begin @test promote(Stencil(1,1;center=1), Stencil(2.,2.;center=2)) == (Stencil(1.,1.;center=1), Stencil(2.,2.;center=2)) end + + @testset "type inference" begin + s_int = CenteredStencil(1,2,3) + s_float = CenteredStencil(1.,2.,3.) + v_int = rand(1:10,10); + v_float = rand(10); + + @inferred SbpOperators.apply_stencil(s_int, v_int, 2) + @inferred SbpOperators.apply_stencil(s_float, v_float, 2) + @inferred SbpOperators.apply_stencil(s_int, v_float, 2) + @inferred SbpOperators.apply_stencil(s_float, v_int, 2) + end end @testset "NestedStencil" begin