|
5 | 5 | A2 = rand(Float64, N1, N1) * 100 |
6 | 6 | A3 = rand(Float64, N1, N1, N1) * 100 |
7 | 7 |
|
8 | | - for (constructor, copier) in ((interpolate, x->x), (interpolate!, copy)) |
9 | | - isinplace = constructor == interpolate! |
10 | | - itp1 = @inferred(constructor(copier(A1), BSpline(Constant()))) |
11 | | - itp2 = @inferred(constructor(copier(A2), BSpline(Constant()))) |
12 | | - itp3 = @inferred(constructor(copier(A3), BSpline(Constant()))) |
13 | | - |
14 | | - @test parent(itp1) === itp1.coefs |
15 | | - @test Interpolations.lbounds(itp1) == (1,) |
16 | | - @test Interpolations.ubounds(itp1) == (N1,) |
17 | | - |
18 | | - # Evaluation on provided data points |
19 | | - for (itp, A) in ((itp1, A1), (itp2, A2), (itp3, A3)) |
20 | | - check_axes(itp, A, isinplace) |
21 | | - check_inbounds_values(itp, A) |
22 | | - check_oob(itp) |
23 | | - can_eval_near_boundaries(itp) |
24 | | - end |
| 8 | + @testset "Constant{Nearest}" begin |
| 9 | + for (constructor, copier) in ((interpolate, x -> x), (interpolate!, copy)) |
| 10 | + isinplace = constructor == interpolate! |
| 11 | + itp1 = @inferred(constructor(copier(A1), BSpline(Constant()))) |
| 12 | + itp2 = @inferred(constructor(copier(A2), BSpline(Constant()))) |
| 13 | + itp3 = @inferred(constructor(copier(A3), BSpline(Constant()))) |
| 14 | + |
| 15 | + @test parent(itp1) === itp1.coefs |
| 16 | + @test Interpolations.lbounds(itp1) == (1,) |
| 17 | + @test Interpolations.ubounds(itp1) == (N1,) |
25 | 18 |
|
26 | | - # Evaluation between data points (tests constancy) |
27 | | - for i in 2:N1-1 |
28 | | - @test A1[i] == itp1(i+.3) == itp1(i+.3) == itp1(i-.3) == itp1(i-.3) |
| 19 | + # Evaluation on provided data points |
| 20 | + for (itp, A) in ((itp1, A1), (itp2, A2), (itp3, A3)) |
| 21 | + check_axes(itp, A, isinplace) |
| 22 | + check_inbounds_values(itp, A) |
| 23 | + check_oob(itp) |
| 24 | + can_eval_near_boundaries(itp) |
| 25 | + end |
| 26 | + |
| 27 | + # Evaluation between data points (tests constancy) |
| 28 | + for i in 2:N1 - 1 |
| 29 | + @test A1[i] == itp1(i + .3) == itp1(i - .3) |
| 30 | + end |
| 31 | + # 2D |
| 32 | + for i in 2:N1 - 1, j in 2:N1 - 1 |
| 33 | + @test A2[i,j] == itp2(i + .4, j - .3) == itp2(i - .4, j + .3) |
| 34 | + end |
| 35 | + # 3D |
| 36 | + for i in 2:N1 - 1, j in 2:N1 - 1, k in 2:N1 - 1 |
| 37 | + @test A3[i,j,k] == itp3(i + .4, j - .3, k + .1) == itp3(i + .4, j - .3, k + .2) |
| 38 | + end |
29 | 39 | end |
30 | | - # 2D |
31 | | - for i in 2:N1-1, j in 2:N1-1 |
32 | | - @test A2[i,j] == itp2(i+.4,j-.3) == itp2(i+.4,j-.3) |
| 40 | + end |
| 41 | + |
| 42 | + @testset "Constant{Previous}" begin |
| 43 | + for (constructor, copier) in ((interpolate, x -> x), (interpolate!, copy)) |
| 44 | + isinplace = constructor == interpolate! |
| 45 | + itp1 = @inferred(constructor(copier(A1), BSpline(Constant{Previous}()))) |
| 46 | + itp2 = @inferred(constructor(copier(A2), BSpline(Constant{Previous}()))) |
| 47 | + itp3 = @inferred(constructor(copier(A3), BSpline(Constant{Previous}()))) |
| 48 | + |
| 49 | + @test parent(itp1) === itp1.coefs |
| 50 | + @test Interpolations.lbounds(itp1) == (1,) |
| 51 | + @test Interpolations.ubounds(itp1) == (N1,) |
| 52 | + |
| 53 | + # Evaluation on provided data points |
| 54 | + for (itp, A) in ((itp1, A1), (itp2, A2), (itp3, A3)) |
| 55 | + check_axes(itp, A, isinplace) |
| 56 | + check_inbounds_values(itp, A) |
| 57 | + check_oob(itp) |
| 58 | + can_eval_near_boundaries(itp) |
| 59 | + end |
| 60 | + |
| 61 | + # Evaluation between data points (tests constancy) |
| 62 | + for i in 2:N1 - 1 |
| 63 | + @test A1[i] == itp1(i + .3) == itp1(i + .6) |
| 64 | + @test A1[i - 1] == itp1(i - .3) == itp1(i - .6) |
| 65 | + end |
| 66 | + # 2D |
| 67 | + for i in 2:N1 - 1, j in 2:N1 - 1 |
| 68 | + @test A2[i,j - 1] == itp2(i + .4, j - .3) == itp2(i + .4, j - .6) |
| 69 | + end |
| 70 | + # 3D |
| 71 | + for i in 2:N1 - 1, j in 2:N1 - 1, k in 2:N1 - 1 |
| 72 | + @test A3[i,j - 1,k] == itp3(i + .4, j - .3, k + .1) == itp3(i + .4, j - .3, k + .2) |
| 73 | + end |
33 | 74 | end |
34 | | - # 3D |
35 | | - for i in 2:N1-1, j in 2:N1-1, k in 2:N1-1 |
36 | | - @test A3[i,j,k] == itp3(i+.4,j-.3,k+.1) == itp3(i+.4,j-.3,k+.2) |
| 75 | + end |
| 76 | + |
| 77 | + @testset "Constant{Next}" begin |
| 78 | + for (constructor, copier) in ((interpolate, x -> x), (interpolate!, copy)) |
| 79 | + isinplace = constructor == interpolate! |
| 80 | + itp1 = @inferred(constructor(copier(A1), BSpline(Constant{Next}()))) |
| 81 | + itp2 = @inferred(constructor(copier(A2), BSpline(Constant{Next}()))) |
| 82 | + itp3 = @inferred(constructor(copier(A3), BSpline(Constant{Next}()))) |
| 83 | + |
| 84 | + @test parent(itp1) === itp1.coefs |
| 85 | + @test Interpolations.lbounds(itp1) == (1,) |
| 86 | + @test Interpolations.ubounds(itp1) == (N1,) |
| 87 | + |
| 88 | + # Evaluation on provided data points |
| 89 | + for (itp, A) in ((itp1, A1), (itp2, A2), (itp3, A3)) |
| 90 | + check_axes(itp, A, isinplace) |
| 91 | + check_inbounds_values(itp, A) |
| 92 | + check_oob(itp) |
| 93 | + can_eval_near_boundaries(itp) |
| 94 | + end |
| 95 | + |
| 96 | + # Evaluation between data points (tests constancy) |
| 97 | + for i in 2:N1 - 1 |
| 98 | + @test A1[i + 1] == itp1(i + .3) == itp1(i + .6) |
| 99 | + @test A1[i] == itp1(i - .3) == itp1(i - .6) |
| 100 | + end |
| 101 | + # 2D |
| 102 | + for i in 2:N1 - 1, j in 2:N1 - 1 |
| 103 | + @test A2[i + 1,j] == itp2(i + .4, j - .3) == itp2(i + .4, j - .6) |
| 104 | + end |
| 105 | + # 3D |
| 106 | + for i in 2:N1 - 1, j in 2:N1 - 1, k in 2:N1 - 1 |
| 107 | + @test A3[i + 1,j,k + 1] == itp3(i + .4, j - .3, k + .1) == itp3(i + .4, j - .3, k + .2) |
| 108 | + end |
37 | 109 | end |
38 | 110 | end |
39 | 111 | end |
| 112 | + |
0 commit comments