|
1 |
| -module ConstantTests |
2 |
| - |
3 |
| -using Interpolations |
4 |
| -using Test |
5 |
| - |
6 |
| -# Instantiation |
7 |
| -N1 = 10 |
8 |
| -A1 = rand(Float64, N1) * 100 |
9 |
| -A2 = rand(Float64, N1, N1) * 100 |
10 |
| -A3 = rand(Float64, N1, N1, N1) * 100 |
11 |
| - |
12 |
| -getindexib(itp, i...) = @inbounds itp[i...] |
13 |
| -callib(itp, i...) = @inbounds itp(i...) |
14 |
| - |
15 |
| -for (constructor, copier) in ((interpolate, x->x), (interpolate!, copy)) |
16 |
| - itp1c = @inferred(constructor(copier(A1), BSpline(Constant()), OnCell())) |
17 |
| - itp1g = @inferred(constructor(copier(A1), BSpline(Constant()), OnGrid())) |
18 |
| - itp2c = @inferred(constructor(copier(A2), BSpline(Constant()), OnCell())) |
19 |
| - itp2g = @inferred(constructor(copier(A2), BSpline(Constant()), OnGrid())) |
20 |
| - itp3c = @inferred(constructor(copier(A3), BSpline(Constant()), OnCell())) |
21 |
| - itp3g = @inferred(constructor(copier(A3), BSpline(Constant()), OnGrid())) |
22 |
| - |
23 |
| - @test parent(itp1c) === itp1c.coefs |
| 1 | +@testset "Constant" begin |
| 2 | + # Instantiation |
| 3 | + N1 = 10 |
| 4 | + A1 = rand(Float64, N1) * 100 |
| 5 | + A2 = rand(Float64, N1, N1) * 100 |
| 6 | + A3 = rand(Float64, N1, N1, N1) * 100 |
| 7 | + |
| 8 | + for (constructor, copier) in ((interpolate, x->x), (interpolate!, copy)) |
| 9 | + isinplace = constructor == interpolate! |
| 10 | + itp1c = @inferred(constructor(copier(A1), BSpline(Constant()), OnCell())) |
| 11 | + itp1g = @inferred(constructor(copier(A1), BSpline(Constant()), OnGrid())) |
| 12 | + itp2c = @inferred(constructor(copier(A2), BSpline(Constant()), OnCell())) |
| 13 | + itp2g = @inferred(constructor(copier(A2), BSpline(Constant()), OnGrid())) |
| 14 | + itp3c = @inferred(constructor(copier(A3), BSpline(Constant()), OnCell())) |
| 15 | + itp3g = @inferred(constructor(copier(A3), BSpline(Constant()), OnGrid())) |
| 16 | + |
| 17 | + @test parent(itp1c) === itp1c.coefs |
| 18 | + @test Interpolations.lbounds(itp1c) == (0.5,) |
| 19 | + @test Interpolations.lbounds(itp1g) == (1,) |
| 20 | + @test Interpolations.ubounds(itp1c) == (N1 + 0.5,) |
| 21 | + @test Interpolations.ubounds(itp1g) == (N1,) |
| 22 | + |
| 23 | + # Evaluation on provided data points |
| 24 | + for (itp, A) in ((itp1c, A1), (itp1g, A1), (itp2c, A2), (itp2g, A2), (itp3c, A3), (itp3g, A3)) |
| 25 | + check_axes(itp, A, isinplace) |
| 26 | + check_inbounds_values(itp, A) |
| 27 | + check_oob(itp) |
| 28 | + can_eval_near_boundaries(itp) |
| 29 | + end |
24 | 30 |
|
25 |
| - # Evaluation on provided data points |
26 |
| - for (itp, A) in ((itp1c, A1), (itp1g, A1), (itp2c, A2), (itp2g, A2), (itp3c, A3), (itp3g, A3)) |
27 |
| - for i in eachindex(itp) |
28 |
| - @test A[i] == itp[i] == itp[Tuple(i)...] == itp(i) == itp(float.(Tuple(i))...) |
| 31 | + # Evaluation between data points (tests constancy) |
| 32 | + for i in 2:N1-1 |
| 33 | + @test A1[i] == itp1c(i+.3) == itp1g(i+.3) == itp1c(i-.3) == itp1g(i-.3) |
29 | 34 | end
|
30 |
| - @test @inferred(axes(itp)) == axes(A) |
31 |
| - @test @inferred(size(itp)) == size(A) |
32 |
| - # @test @inferred(axes(itp)) == (contructor == interpolate ? (1:N1) : (2:N1-1)) |
33 |
| - # @test @inferred(size(itp)) == (contructor == interpolate ? N1 : N1-2) |
34 |
| - end |
35 |
| - for itp in (itp1c, itp1g) |
36 |
| - for i = 1:N1 |
37 |
| - @test itp[i,1] == A1[i] # used in the AbstractArray display infrastructure |
38 |
| - @test_throws BoundsError itp[i,2] |
39 |
| - @test_broken getindexib(itp, i, 2) == A1[i] |
40 |
| - @test_broken callib(itp, i, 2) == A1[i] |
| 35 | + # 2D |
| 36 | + for i in 2:N1-1, j in 2:N1-1 |
| 37 | + @test A2[i,j] == itp2c(i+.4,j-.3) == itp2g(i+.4,j-.3) |
| 38 | + end |
| 39 | + # 3D |
| 40 | + for i in 2:N1-1, j in 2:N1-1, k in 2:N1-1 |
| 41 | + @test A3[i,j,k] == itp3c(i+.4,j-.3,k+.1) == itp3g(i+.4,j-.3,k+.2) |
41 | 42 | end
|
42 |
| - end |
43 | 43 |
|
44 |
| - # Evaluation between data points (tests constancy) |
45 |
| - for i in 2:N1-1 |
46 |
| - @test A1[i] == itp1c(i+.3) == itp1g(i+.3) == itp1c(i-.3) == itp1g(i-.3) |
47 |
| - end |
48 |
| - # 2D |
49 |
| - for i in 2:N1-1, j in 2:N1-1 |
50 |
| - @test A2[i,j] == itp2c(i+.4,j-.3) == itp2g(i+.4,j-.3) |
51 |
| - end |
52 |
| - # 3D |
53 |
| - for i in 2:N1-1, j in 2:N1-1, k in 2:N1-1 |
54 |
| - @test A3[i,j,k] == itp3c(i+.4,j-.3,k+.1) == itp3g(i+.4,j-.3,k+.2) |
| 44 | + # Edge behavior |
| 45 | + @test A1[1] == itp1c(.7) |
| 46 | + @test A1[N1] == itp1c(N1+.3) |
55 | 47 | end
|
56 |
| - |
57 |
| - # Edge behavior |
58 |
| - @test A1[1] == itp1c(.7) |
59 |
| - @test A1[N1] == itp1c(N1+.3) |
60 |
| -end |
61 |
| - |
62 | 48 | end
|
0 commit comments