changeset 1057:0728e84af0dc feature/nested_stencils

Add length method for stencils (grafted from 0be29e65521e8a5183c81d90c1163fe7c93dfffe)
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 07 Feb 2022 14:34:03 +0100
parents fe83ea1db953
children c4f71d6f2d63
files src/SbpOperators/stencil.jl test/SbpOperators/stencil_test.jl
diffstat 2 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
diff -r fe83ea1db953 -r 0728e84af0dc src/SbpOperators/stencil.jl
--- a/src/SbpOperators/stencil.jl	Thu Jan 20 15:17:37 2022 +0100
+++ b/src/SbpOperators/stencil.jl	Mon Feb 07 14:34:03 2022 +0100
@@ -49,7 +49,8 @@
     return Stencil(s.range, a.*s.weights)
 end
 
-Base.eltype(::Stencil{T}) where T = T
+Base.eltype(::Stencil{T,N}) where {T,N} = T
+Base.length(::Stencil{T,N}) where {T,N} = N
 
 function flip(s::Stencil)
     range = (-s.range[2], -s.range[1])
diff -r fe83ea1db953 -r 0728e84af0dc test/SbpOperators/stencil_test.jl
--- a/test/SbpOperators/stencil_test.jl	Thu Jan 20 15:17:37 2022 +0100
+++ b/test/SbpOperators/stencil_test.jl	Mon Feb 07 14:34:03 2022 +0100
@@ -9,6 +9,10 @@
     @test s isa Stencil{Float64, 5}
 
     @test eltype(s) == Float64
+
+    @test length(s) == 5
+    @test length(Stencil((-1,2), (1,2,3,4))) == 4
+
     @test SbpOperators.scale(s, 2) == Stencil((-2,2), (2.,4.,4.,6.,8.))
 
     @test Stencil(1,2,3,4; center=1) == Stencil((0, 3),(1,2,3,4))