Mercurial > repos > public > sbplib_julia
comparison src/SbpOperators/stencil.jl @ 823:3c1dd7692797
Merge refactor/sbp_operators_method_signatures
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Thu, 13 Jan 2022 12:43:10 +0100 |
| parents | 1fc6c4daec44 |
| children | 4433be383840 |
comparison
equal
deleted
inserted
replaced
| 817:a1d556611e3c | 823:3c1dd7692797 |
|---|---|
| 1 export CenteredStencil | 1 export CenteredStencil |
| 2 | 2 |
| 3 struct Stencil{T<:Real,N} | 3 struct Stencil{T,N} |
| 4 range::Tuple{Int,Int} | 4 range::Tuple{Int,Int} |
| 5 weights::NTuple{N,T} | 5 weights::NTuple{N,T} |
| 6 | 6 |
| 7 function Stencil(range::Tuple{Int,Int},weights::NTuple{N,T}) where {T <: Real, N} | 7 function Stencil(range::Tuple{Int,Int},weights::NTuple{N,T}) where {T, N} |
| 8 @assert range[2]-range[1]+1 == N | 8 @assert range[2]-range[1]+1 == N |
| 9 new{T,N}(range,weights) | 9 new{T,N}(range,weights) |
| 10 end | 10 end |
| 11 end | 11 end |
| 12 | 12 |
| 13 """ | 13 """ |
| 14 Stencil(weights::NTuple; center::Int) | 14 Stencil(weights::NTuple; center::Int) |
| 15 | 15 |
| 16 Create a stencil with the given weights with element `center` as the center of the stencil. | 16 Create a stencil with the given weights with element `center` as the center of the stencil. |
| 17 """ | 17 """ |
| 18 function Stencil(weights::Vararg{Number}; center::Int) | 18 function Stencil(weights::Vararg{T}; center::Int) where T # Type parameter T makes sure the weights are valid for the Stencil constuctors and throws an earlier, more readable, error |
| 19 N = length(weights) | 19 N = length(weights) |
| 20 range = (1, N) .- center | 20 range = (1, N) .- center |
| 21 | 21 |
| 22 return Stencil(range, weights) | 22 return Stencil(range, weights) |
| 23 end | 23 end |
