Mercurial > repos > public > sbplib_julia
diff src/SbpOperators/stencil.jl @ 671:e14627e79a54 feature/stencil_convenience
Add stencil constructor for centered stencils and change from tuple to vararg in stencil constructor taking cneter
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sat, 06 Feb 2021 21:42:57 +0100 |
parents | 03ef4d4740ab |
children | 59a81254fefc |
line wrap: on
line diff
--- a/src/SbpOperators/stencil.jl Sun Jan 31 20:57:58 2021 +0100 +++ b/src/SbpOperators/stencil.jl Sat Feb 06 21:42:57 2021 +0100 @@ -1,3 +1,5 @@ +export CenteredStencil + struct Stencil{T<:Real,N} range::Tuple{Int,Int} weights::NTuple{N,T} @@ -13,13 +15,24 @@ Create a stencil with the given weights with element `center` as the center of the stencil. """ -function Stencil(weights::NTuple; center::Int) +function Stencil(weights::Vararg{Number}; center::Int) N = length(weights) range = (1, N) .- center return Stencil(range, weights) end + +function CenteredStencil(weights::Vararg) + if iseven(length(weights)) + throw(ArgumentError("a centered stencil must have an odd number of weights.")) + end + + r = length(weights) รท 2 + + return Stencil((-r, r), weights) +end + """ scale(s::Stencil, a)