Skip to content

Commit af4d43b

Browse files
simplify tests
1 parent 7dde9d2 commit af4d43b

File tree

11 files changed

+98
-154
lines changed

11 files changed

+98
-154
lines changed

test/FixedSizeDiffCache/core_dispatch.jl

Lines changed: 0 additions & 50 deletions
This file was deleted.

test/FixedSizeDiffCache/core_odes.jl

Lines changed: 0 additions & 27 deletions
This file was deleted.

test/FixedSizeDiffCache/core_resizing.jl

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/FixedSizeDiffCache/gpu_all.jl

Lines changed: 0 additions & 45 deletions
This file was deleted.

test/DiffCache/core_dispatch.jl renamed to test/core_dispatch.jl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,28 @@ results = test(u0, dual, chunk_size)
4141
@test eltype(results[5]) == eltype(u0)
4242
@test eltype(results[7]) == eltype(dual)
4343

44+
chunk_size = 5
45+
u0_B = ones(5, 5)
46+
dual_B = zeros(ForwardDiff.Dual{ForwardDiff.Tag{typeof(something), Float64}, Float64,
47+
chunk_size}, 2, 2)
48+
cache_B = FixedSizeDiffCache(u0_B, chunk_size)
49+
tmp_du_BA = get_tmp(cache_B, u0_B)
50+
tmp_dual_du_BA = get_tmp(cache_B, dual_B)
51+
tmp_du_BN = get_tmp(cache_B, u0_B[1])
52+
tmp_dual_du_BN = get_tmp(cache_B, dual_B[1])
53+
@test size(tmp_du_BA) == size(u0_B)
54+
@test typeof(tmp_du_BA) == typeof(u0_B)
55+
@test eltype(tmp_du_BA) == eltype(u0_B)
56+
@test size(tmp_dual_du_BA) == size(u0_B)
57+
@test_broken typeof(tmp_dual_du_BA) == typeof(dual_B)
58+
@test eltype(tmp_dual_du_BA) == eltype(dual_B)
59+
@test size(tmp_du_BN) == size(u0_B)
60+
@test typeof(tmp_du_BN) == typeof(u0_B)
61+
@test eltype(tmp_du_BN) == eltype(u0_B)
62+
@test size(tmp_dual_du_BN) == size(u0_B)
63+
@test_broken typeof(tmp_dual_du_BN) == typeof(dual_B)
64+
@test eltype(tmp_dual_du_BN) == eltype(dual_B)
65+
4466
#LArray tests
4567
chunk_size = 4
4668
u0 = LArray((2, 2); a = 1.0, b = 1.0, c = 1.0, d = 1.0)
@@ -94,3 +116,27 @@ results = test(u0, dual, chunk_size)
94116
#eltype tests
95117
@test eltype(results[5]) == eltype(u0)
96118
@test eltype(results[7]) == eltype(dual)
119+
120+
u0_AP = ArrayPartition(ones(2, 2), ones(3, 3))
121+
dual_a = zeros(ForwardDiff.Dual{ForwardDiff.Tag{typeof(something), Float64}, Float64,
122+
chunk_size}, 2, 2)
123+
dual_b = zeros(ForwardDiff.Dual{ForwardDiff.Tag{typeof(something), Float64}, Float64,
124+
chunk_size}, 3, 3)
125+
dual_AP = ArrayPartition(dual_a, dual_b)
126+
cache_AP = FixedSizeDiffCache(u0_AP, chunk_size)
127+
tmp_du_APA = get_tmp(cache_AP, u0_AP)
128+
tmp_dual_du_APA = get_tmp(cache_AP, dual_AP)
129+
tmp_du_APN = get_tmp(cache_AP, u0_AP[1])
130+
tmp_dual_du_APN = get_tmp(cache_AP, dual_AP[1])
131+
@test size(tmp_du_APA) == size(u0_AP)
132+
@test typeof(tmp_du_APA) == typeof(u0_AP)
133+
@test eltype(tmp_du_APA) == eltype(u0_AP)
134+
@test size(tmp_dual_du_APA) == size(u0_AP)
135+
@test_broken typeof(tmp_dual_du_APA) == typeof(dual_AP)
136+
@test eltype(tmp_dual_du_APA) == eltype(dual_AP)
137+
@test size(tmp_du_APN) == size(u0_AP)
138+
@test typeof(tmp_du_APN) == typeof(u0_AP)
139+
@test eltype(tmp_du_APN) == eltype(u0_AP)
140+
@test size(tmp_dual_du_APN) == size(u0_AP)
141+
@test_broken typeof(tmp_dual_du_APN) == typeof(dual_AP)
142+
@test eltype(tmp_dual_du_APN) == eltype(dual_AP)
File renamed without changes.

test/DiffCache/core_odes.jl renamed to test/core_odes.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using LinearAlgebra, OrdinaryDiffEq, Test, PreallocationTools, LabelledArrays,
22
RecursiveArrayTools
33

4+
# upstream
5+
OrdinaryDiffEq.DiffEqBase.anyeltypedual(x::FixedSizeDiffCache, counter = 0) = Any
6+
47
#Base array
58
function foo(du, u, (A, tmp), t)
69
tmp = get_tmp(tmp, u)
@@ -17,12 +20,22 @@ prob = ODEProblem{true, SciMLBase.FullSpecialize}(foo, u0, (0.0, 1.0), (A, cache
1720
sol = solve(prob, TRBDF2(chunk_size = chunk_size))
1821
@test sol.retcode == ReturnCode.Success
1922

23+
cache = FixedSizeDiffCache(zeros(5, 5), chunk_size)
24+
prob = ODEProblem{true, SciMLBase.FullSpecialize}(foo, u0, (0.0, 1.0), (A, cache))
25+
sol = solve(prob, TRBDF2(chunk_size = chunk_size))
26+
@test sol.retcode == ReturnCode.Success
27+
2028
#with auto-detected chunk_size
2129
cache = DiffCache(zeros(5, 5))
2230
prob = ODEProblem{true, SciMLBase.FullSpecialize}(foo, ones(5, 5), (0.0, 1.0), (A, cache))
2331
sol = solve(prob, TRBDF2())
2432
@test sol.retcode == ReturnCode.Success
2533

34+
prob = ODEProblem(foo, ones(5, 5), (0.0, 1.0),
35+
(ones(5, 5), FixedSizeDiffCache(zeros(5, 5))))
36+
sol = solve(prob, TRBDF2())
37+
@test sol.retcode == ReturnCode.Success
38+
2639
#Base array with LBC
2740
function foo(du, u, (A, lbc), t)
2841
tmp = lbc[u]

test/DiffCache/core_resizing.jl renamed to test/core_resizing.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ end
2424
df1 = ForwardDiff.derivative-> claytonsample!(stod, τ, 0.0), 0.3)
2525
@test size(randmat) == size(df1)
2626

27+
stod = FixedSizeDiffCache(sto)
28+
ForwardDiff.derivative-> claytonsample!(stod, τ), 0.3)
29+
@test size(randmat) == size(df1)
30+
2731
#calculating the jacobian of claytonsample! with respect to τ and α
2832
df2 = ForwardDiff.jacobian(x -> claytonsample!(stod, x[1], x[2]), [0.3; 0.0]) #should give a 15x2 array,
2933
#because ForwardDiff flattens the output of jacobian, see: https://juliadiff.org/ForwardDiff.jl/stable/user/api/#ForwardDiff.jacobian

test/DiffCache/gpu_all.jl renamed to test/gpu_all.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using LinearAlgebra, OrdinaryDiffEq, Test, PreallocationTools, CUDA, ForwardDiff,
22
ArrayInterfaceCore
33

4+
# upstream
5+
OrdinaryDiffEq.DiffEqBase.anyeltypedual(x::FixedSizeDiffCache, counter = 0) = Any
6+
47
#Dispatch tests
58
chunk_size = 5
69
u0_CU = cu(ones(5, 5))
@@ -27,6 +30,20 @@ tmp_dual_du_CUN = get_tmp(cache_CU, dual_N)
2730
@test typeof(tmp_dual_du_CUN) == typeof(dual_CU)
2831
@test eltype(tmp_dual_du_CUN) == eltype(dual_CU)
2932

33+
chunk_size = 5
34+
u0_B = cu(ones(5, 5))
35+
dual_B = cu(zeros(ForwardDiff.Dual{ForwardDiff.Tag{typeof(something), Float32}, Float32,
36+
chunk_size}, 2, 2))
37+
cache_B = FixedSizeDiffCache(u0_B, chunk_size)
38+
tmp_du_BA = get_tmp(cache_B, u0_B)
39+
tmp_dual_du_BA = get_tmp(cache_B, dual_B)
40+
@test size(tmp_du_BA) == size(u0_B)
41+
@test typeof(tmp_du_BA) == typeof(u0_B)
42+
@test eltype(tmp_du_BA) == eltype(u0_B)
43+
@test size(tmp_dual_du_BA) == size(u0_B)
44+
@test typeof(tmp_dual_du_BA) == typeof(dual_B)
45+
@test eltype(tmp_dual_du_BA) == eltype(dual_B)
46+
3047
#ODE tests
3148
function foo(du, u, (A, tmp), t)
3249
tmp = get_tmp(tmp, u)
@@ -43,6 +60,11 @@ prob = ODEProblem{true, SciMLBase.FullSpecialize}(foo, u0, (0.0f0, 1.0f0), (A, c
4360
sol = solve(prob, TRBDF2(chunk_size = chunk_size))
4461
@test sol.retcode == ReturnCode.Success
4562

63+
cache = FixedSizeDiffCache(cu(zeros(5, 5)), chunk_size)
64+
prob = ODEProblem{true, SciMLBase.FullSpecialize}(foo, u0, (0.0f0, 1.0f0), (A, cache))
65+
sol = solve(prob, TRBDF2(chunk_size = chunk_size))
66+
@test sol.retcode == ReturnCode.Success
67+
4668
#with auto-detected chunk_size
4769
u0 = cu(rand(10, 10)) #example kept small for test purposes.
4870
A = cu(-randn(10, 10))
@@ -51,6 +73,13 @@ prob = ODEProblem{true, SciMLBase.FullSpecialize}(foo, u0, (0.0f0, 1.0f0), (A, c
5173
sol = solve(prob, TRBDF2())
5274
@test sol.retcode == ReturnCode.Success
5375

76+
u0 = cu(rand(10, 10)) #example kept small for test purposes.
77+
A = cu(-randn(10, 10))
78+
cache = FixedSizeDiffCache(A)
79+
prob = ODEProblem(foo, u0, (0.0f0, 1.0f0), (A, cache))
80+
sol = solve(prob, TRBDF2())
81+
@test sol.retcode == ReturnCode.Success
82+
5483
#resizing tests
5584
randmat = cu(rand(5, 3))
5685
sto = similar(randmat)

test/runtests.jl

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,14 @@ function activate_downstream_env()
1111
end
1212

1313
if GROUP == "All" || GROUP == "Core"
14-
@safetestset "DiffCache Dispatch" begin include("DiffCache/core_dispatch.jl") end
15-
@safetestset "DiffCache ODE tests" begin include("DiffCache/core_odes.jl") end
16-
@safetestset "DiffCache Resizing" begin include("DiffCache/core_resizing.jl") end
17-
@safetestset "DiffCache Nested Duals" begin include("DiffCache/core_nesteddual.jl") end
18-
@safetestset "DiffCache Sparsity Support" begin include("DiffCache/sparsity_support.jl") end
19-
20-
@safetestset "FixedSizeDiffCache Dispatch" begin include("FixedSizeDiffCache/core_dispatch.jl") end
21-
@safetestset "FixedSizeDiffCache ODE tests" begin include("FixedSizeDiffCache/core_odes.jl") end
22-
@safetestset "FixedSizeDiffCache Base Array Resizing" begin include("FixedSizeDiffCache/core_resizing.jl") end
14+
@safetestset "DiffCache Dispatch" begin include("core_dispatch.jl") end
15+
@safetestset "DiffCache ODE tests" begin include("core_odes.jl") end
16+
@safetestset "DiffCache Resizing" begin include("core_resizing.jl") end
17+
@safetestset "DiffCache Nested Duals" begin include("core_nesteddual.jl") end
18+
@safetestset "DiffCache Sparsity Support" begin include("sparsity_support.jl") end
2319
end
2420

2521
if !is_APPVEYOR && GROUP == "GPU"
2622
activate_downstream_env()
27-
@safetestset "GPU tests" begin include("FixedSizeDiffCache/gpu_all.jl") end
28-
@safetestset "GPU tests" begin include("DiffCache/gpu_all.jl") end
23+
@safetestset "GPU tests" begin include("gpu_all.jl") end
2924
end

0 commit comments

Comments
 (0)