|
1 |
| -using LinearAlgebra, OrdinaryDiffEq, Test, PreallocationTools, ForwardDiff, LabelledArrays, |
| 1 | +using LinearAlgebra, Test, PreallocationTools, ForwardDiff, LabelledArrays, |
2 | 2 | RecursiveArrayTools
|
3 | 3 |
|
4 |
| -#Base Array tests |
| 4 | +function test(u0, dual, chunk_size) |
| 5 | + cache = PreallocationTools.dualcache(u0, chunk_size) |
| 6 | + allocs_normal1 = @allocated get_tmp(cache, u0) |
| 7 | + allocs_normal2 = @allocated get_tmp(cache, first(u0)) |
| 8 | + allocs_dual1 = @allocated get_tmp(cache, dual) |
| 9 | + allocs_dual2 = @allocated get_tmp(cache, first(dual)) |
| 10 | + result_normal1 = get_tmp(cache, u0) |
| 11 | + result_normal2 = get_tmp(cache, first(u0)) |
| 12 | + result_dual1 = get_tmp(cache, dual) |
| 13 | + result_dual2 = get_tmp(cache, first(dual)) |
| 14 | + return allocs_normal1, allocs_normal2, allocs_dual1, allocs_dual2, result_normal1, |
| 15 | + result_normal2, result_dual1, |
| 16 | + result_dual2 |
| 17 | +end |
| 18 | + |
| 19 | +#Setup Base Array tests |
5 | 20 | chunk_size = 5
|
6 |
| -u0_B = ones(5, 5) |
7 |
| -dual_B = zeros(ForwardDiff.Dual{ForwardDiff.Tag{typeof(something), Float64}, Float64, |
8 |
| - chunk_size}, 2, 2) |
9 |
| -cache_B = dualcache(u0_B, chunk_size) |
10 |
| -tmp_du_BA = get_tmp(cache_B, u0_B) |
11 |
| -tmp_dual_du_BA = get_tmp(cache_B, dual_B) |
12 |
| -tmp_du_BN = get_tmp(cache_B, u0_B[1]) |
13 |
| -tmp_dual_du_BN = get_tmp(cache_B, dual_B[1]) |
14 |
| -@test size(tmp_du_BA) == size(u0_B) |
15 |
| -@test typeof(tmp_du_BA) == typeof(u0_B) |
16 |
| -@test eltype(tmp_du_BA) == eltype(u0_B) |
17 |
| -@test size(tmp_dual_du_BA) == size(u0_B) |
18 |
| -@test typeof(tmp_dual_du_BA) == typeof(dual_B) |
19 |
| -@test eltype(tmp_dual_du_BA) == eltype(dual_B) |
20 |
| -@test size(tmp_du_BN) == size(u0_B) |
21 |
| -@test typeof(tmp_du_BN) == typeof(u0_B) |
22 |
| -@test eltype(tmp_du_BN) == eltype(u0_B) |
23 |
| -@test size(tmp_dual_du_BN) == size(u0_B) |
24 |
| -@test typeof(tmp_dual_du_BN) == typeof(dual_B) |
25 |
| -@test eltype(tmp_dual_du_BN) == eltype(dual_B) |
| 21 | +u0 = ones(5, 5) |
| 22 | +dual = zeros(ForwardDiff.Dual{ForwardDiff.Tag{nothing, Float64}, Float64, |
| 23 | + chunk_size}, 5, 5) |
| 24 | +results = test(u0, dual, chunk_size) |
| 25 | +#allocation tests |
| 26 | +@test results[1] == 0 |
| 27 | +@test results[2] == 0 |
| 28 | +@test results[3] == 0 |
| 29 | +@test results[4] == 0 |
| 30 | +#size tests |
| 31 | +@test size(results[5]) == size(u0) |
| 32 | +@test size(results[6]) == size(u0) |
| 33 | +@test size(results[7]) == size(u0) |
| 34 | +@test size(results[8]) == size(u0) |
| 35 | +#type tests |
| 36 | +@test typeof(results[5]) == typeof(u0) |
| 37 | +@test typeof(results[6]) == typeof(u0) |
| 38 | +@test_broken typeof(results[7]) == typeof(dual) |
| 39 | +@test_broken typeof(results[8]) == typeof(dual) |
| 40 | +#eltype tests |
| 41 | +@test eltype(results[5]) == eltype(u0) |
| 42 | +@test eltype(results[7]) == eltype(dual) |
26 | 43 |
|
27 | 44 | #LArray tests
|
28 | 45 | chunk_size = 4
|
29 |
| -u0_L = LArray((2, 2); a = 1.0, b = 1.0, c = 1.0, d = 1.0) |
30 |
| -zerodual = zero(ForwardDiff.Dual{ForwardDiff.Tag{typeof(something), Float64}, Float64, |
| 46 | +u0 = LArray((2, 2); a = 1.0, b = 1.0, c = 1.0, d = 1.0) |
| 47 | +zerodual = zero(ForwardDiff.Dual{ForwardDiff.Tag{nothing, Float64}, Float64, |
31 | 48 | chunk_size})
|
32 |
| -dual_L = LArray((2, 2); a = zerodual, b = zerodual, c = zerodual, d = zerodual) |
33 |
| -cache_L = dualcache(u0_L, chunk_size) |
34 |
| -tmp_du_LA = get_tmp(cache_L, u0_L) |
35 |
| -tmp_dual_du_LA = get_tmp(cache_L, dual_L) |
36 |
| -tmp_du_LN = get_tmp(cache_L, u0_L[1]) |
37 |
| -tmp_dual_du_LN = get_tmp(cache_L, dual_L[1]) |
38 |
| -@test size(tmp_du_LA) == size(u0_L) |
39 |
| -@test typeof(tmp_du_LA) == typeof(u0_L) |
40 |
| -@test eltype(tmp_du_LA) == eltype(u0_L) |
41 |
| -@test size(tmp_dual_du_LA) == size(u0_L) |
42 |
| -@test typeof(tmp_dual_du_LA) == typeof(dual_L) |
43 |
| -@test eltype(tmp_dual_du_LA) == eltype(dual_L) |
44 |
| -@test size(tmp_du_LN) == size(u0_L) |
45 |
| -@test typeof(tmp_du_LN) == typeof(u0_L) |
46 |
| -@test eltype(tmp_du_LN) == eltype(u0_L) |
47 |
| -@test size(tmp_dual_du_LN) == size(u0_L) |
48 |
| -@test typeof(tmp_dual_du_LN) == typeof(dual_L) |
49 |
| -@test eltype(tmp_dual_du_LN) == eltype(dual_L) |
| 49 | +dual = LArray((2, 2); a = zerodual, b = zerodual, c = zerodual, d = zerodual) |
| 50 | +results = test(u0, dual, chunk_size) |
| 51 | +#allocation tests |
| 52 | +@test results[1] == 0 |
| 53 | +@test results[2] == 0 |
| 54 | +@test_broken results[3] == 0 |
| 55 | +@test_broken results[4] == 0 |
| 56 | +#size tests |
| 57 | +@test size(results[5]) == size(u0) |
| 58 | +@test size(results[6]) == size(u0) |
| 59 | +@test size(results[7]) == size(u0) |
| 60 | +@test size(results[8]) == size(u0) |
| 61 | +#type tests |
| 62 | +@test typeof(results[5]) == typeof(u0) |
| 63 | +@test typeof(results[6]) == typeof(u0) |
| 64 | +@test typeof(results[7]) == typeof(dual) |
| 65 | +@test typeof(results[8]) == typeof(dual) |
| 66 | +#eltype tests |
| 67 | +@test eltype(results[5]) == eltype(u0) |
| 68 | +@test eltype(results[7]) == eltype(dual) |
50 | 69 |
|
51 | 70 | #ArrayPartition tests
|
52 |
| -u0_AP = ArrayPartition(ones(2, 2), ones(3, 3)) |
53 |
| -dual_a = zeros(ForwardDiff.Dual{ForwardDiff.Tag{typeof(something), Float64}, Float64, |
| 71 | +chunk_size = 2 |
| 72 | +u0 = ArrayPartition(ones(2, 2), ones(3, 3)) |
| 73 | +dual_a = zeros(ForwardDiff.Dual{ForwardDiff.Tag{nothing, Float64}, Float64, |
54 | 74 | chunk_size}, 2, 2)
|
55 |
| -dual_b = zeros(ForwardDiff.Dual{ForwardDiff.Tag{typeof(something), Float64}, Float64, |
| 75 | +dual_b = zeros(ForwardDiff.Dual{ForwardDiff.Tag{nothing, Float64}, Float64, |
56 | 76 | chunk_size}, 3, 3)
|
57 |
| -dual_AP = ArrayPartition(dual_a, dual_b) |
58 |
| -cache_AP = dualcache(u0_AP, chunk_size) |
59 |
| -tmp_du_APA = get_tmp(cache_AP, u0_AP) |
60 |
| -tmp_dual_du_APA = get_tmp(cache_AP, dual_AP) |
61 |
| -tmp_du_APN = get_tmp(cache_AP, u0_AP[1]) |
62 |
| -tmp_dual_du_APN = get_tmp(cache_AP, dual_AP[1]) |
63 |
| -@test size(tmp_du_APA) == size(u0_AP) |
64 |
| -@test typeof(tmp_du_APA) == typeof(u0_AP) |
65 |
| -@test eltype(tmp_du_APA) == eltype(u0_AP) |
66 |
| -@test size(tmp_dual_du_APA) == size(u0_AP) |
67 |
| -@test typeof(tmp_dual_du_APA) == typeof(dual_AP) |
68 |
| -@test eltype(tmp_dual_du_APA) == eltype(dual_AP) |
69 |
| -@test size(tmp_du_APN) == size(u0_AP) |
70 |
| -@test typeof(tmp_du_APN) == typeof(u0_AP) |
71 |
| -@test eltype(tmp_du_APN) == eltype(u0_AP) |
72 |
| -@test size(tmp_dual_du_APN) == size(u0_AP) |
73 |
| -@test typeof(tmp_dual_du_APN) == typeof(dual_AP) |
74 |
| -@test eltype(tmp_dual_du_APN) == eltype(dual_AP) |
| 77 | +dual = ArrayPartition(dual_a, dual_b) |
| 78 | +results = test(u0, dual, chunk_size) |
| 79 | +#allocation tests |
| 80 | +@test results[1] == 0 |
| 81 | +@test results[2] == 0 |
| 82 | +@test_broken results[3] == 0 |
| 83 | +@test_broken results[4] == 0 |
| 84 | +#size tests |
| 85 | +@test size(results[5]) == size(u0) |
| 86 | +@test size(results[6]) == size(u0) |
| 87 | +@test size(results[7]) == size(u0) |
| 88 | +@test size(results[8]) == size(u0) |
| 89 | +#type tests |
| 90 | +@test typeof(results[5]) == typeof(u0) |
| 91 | +@test typeof(results[6]) == typeof(u0) |
| 92 | +@test typeof(results[7]) == typeof(dual) |
| 93 | +@test typeof(results[8]) == typeof(dual) |
| 94 | +#eltype tests |
| 95 | +@test eltype(results[5]) == eltype(u0) |
| 96 | +@test eltype(results[7]) == eltype(dual) |
0 commit comments