Mercurial > repos > public > sbplib_julia
comparison test/SbpOperators/stencil_test.jl @ 1060:ff0e819f2075 feature/nested_stencils
Refactor code for regular stencils to use fewer type parameters and allow promotion
(grafted from 737cd68318c7118f9f20a5fbc31431c48962bc71)
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sat, 12 Feb 2022 22:02:06 +0100 |
parents | 4d06642174ec |
children | cd6d71781137 |
comparison
equal
deleted
inserted
replaced
1059:4d06642174ec | 1060:ff0e819f2075 |
---|---|
3 import Sbplib.SbpOperators.Stencil | 3 import Sbplib.SbpOperators.Stencil |
4 import Sbplib.SbpOperators.NestedStencil | 4 import Sbplib.SbpOperators.NestedStencil |
5 import Sbplib.SbpOperators.scale | 5 import Sbplib.SbpOperators.scale |
6 | 6 |
7 @testset "Stencil" begin | 7 @testset "Stencil" begin |
8 s = Stencil((-2,2), (1.,2.,2.,3.,4.)) | 8 s = Stencil(-2:2, (1.,2.,2.,3.,4.)) |
9 @test s isa Stencil{Float64, 5} | 9 @test s isa Stencil{Float64, 5} |
10 | 10 |
11 @test eltype(s) == Float64 | 11 @test eltype(s) == Float64 |
12 | 12 |
13 @test length(s) == 5 | 13 @test length(s) == 5 |
14 @test length(Stencil((-1,2), (1,2,3,4))) == 4 | 14 @test length(Stencil(-1:2, (1,2,3,4))) == 4 |
15 | 15 |
16 @test SbpOperators.scale(s, 2) == Stencil((-2,2), (2.,4.,4.,6.,8.)) | 16 @test SbpOperators.scale(s, 2) == Stencil(-2:2, (2.,4.,4.,6.,8.)) |
17 | 17 |
18 @test Stencil(1,2,3,4; center=1) == Stencil((0, 3),(1,2,3,4)) | 18 @test Stencil(1,2,3,4; center=1) == Stencil(0:3,(1,2,3,4)) |
19 @test Stencil(1,2,3,4; center=2) == Stencil((-1, 2),(1,2,3,4)) | 19 @test Stencil(1,2,3,4; center=2) == Stencil(-1:2,(1,2,3,4)) |
20 @test Stencil(1,2,3,4; center=4) == Stencil((-3, 0),(1,2,3,4)) | 20 @test Stencil(1,2,3,4; center=4) == Stencil(-3:0,(1,2,3,4)) |
21 | 21 |
22 @test CenteredStencil(1,2,3,4,5) == Stencil((-2, 2), (1,2,3,4,5)) | 22 @test CenteredStencil(1,2,3,4,5) == Stencil(-2:2, (1,2,3,4,5)) |
23 @test_throws ArgumentError CenteredStencil(1,2,3,4) | 23 @test_throws ArgumentError CenteredStencil(1,2,3,4) |
24 | 24 |
25 # Changing the type of the weights | 25 # Changing the type of the weights |
26 @test Stencil{Float64}(Stencil(1,2,3,4,5; center=2)) == Stencil(1.,2.,3.,4.,5.; center=2) | 26 @test Stencil{Float64}(Stencil(1,2,3,4,5; center=2)) == Stencil(1.,2.,3.,4.,5.; center=2) |
27 @test Stencil{Float64}(CenteredStencil(1,2,3,4,5)) == CenteredStencil(1.,2.,3.,4.,5.) | 27 @test Stencil{Float64}(CenteredStencil(1,2,3,4,5)) == CenteredStencil(1.,2.,3.,4.,5.) |
28 @test Stencil{Int}(Stencil(1.,2.,3.,4.,5.; center=2)) == Stencil(1,2,3,4,5; center=2) | 28 @test Stencil{Int}(Stencil(1.,2.,3.,4.,5.; center=2)) == Stencil(1,2,3,4,5; center=2) |
29 @test Stencil{Rational}(Stencil(1.,2.,3.,4.,5.; center=2)) == Stencil(1//1,2//1,3//1,4//1,5//1; center=2) | 29 @test Stencil{Rational}(Stencil(1.,2.,3.,4.,5.; center=2)) == Stencil(1//1,2//1,3//1,4//1,5//1; center=2) |
30 | 30 |
31 @testset "convert" begin | 31 @testset "convert" begin |
32 @test convert(Stencil{Float64}, Stencil(1,2,3,4,5; center=2)) == Stencil(1.,2.,3.,4.,5.; center=2) | 32 @test convert(Stencil{Float64}, Stencil(1,2,3,4,5; center=2)) == Stencil(1.,2.,3.,4.,5.; center=2) |
33 @test convert(Stencil{Float64}, CenteredStencil(1,2,3,4,5)) == CenteredStencil(1.,2.,3.,4.,5.) | 33 @test convert(Stencil{Float64,5}, CenteredStencil(1,2,3,4,5)) == CenteredStencil(1.,2.,3.,4.,5.) |
34 @test convert(Stencil{Int}, Stencil(1.,2.,3.,4.,5.; center=2)) == Stencil(1,2,3,4,5; center=2) | 34 @test convert(Stencil{Int,5}, Stencil(1.,2.,3.,4.,5.; center=2)) == Stencil(1,2,3,4,5; center=2) |
35 @test convert(Stencil{Rational}, Stencil(1.,2.,3.,4.,5.; center=2)) == Stencil(1//1,2//1,3//1,4//1,5//1; center=2) | 35 @test convert(Stencil{Rational,5}, Stencil(1.,2.,3.,4.,5.; center=2)) == Stencil(1//1,2//1,3//1,4//1,5//1; center=2) |
36 end | |
37 | |
38 @testset "promotion of weights" begin | |
39 @test Stencil(1.,2; center = 1) isa Stencil{Float64, 2} | |
40 @test Stencil(1,2//2; center = 1) isa Stencil{Rational{Int64}, 2} | |
41 end | |
42 | |
43 @testset "promotion" begin | |
44 @test promote(Stencil(1,1;center=1), Stencil(2.,2.;center=2)) == (Stencil(1.,1.;center=1), Stencil(2.,2.;center=2)) | |
36 end | 45 end |
37 end | 46 end |
38 | 47 |
39 @testset "NestedStencil" begin | 48 @testset "NestedStencil" begin |
40 | 49 |