Skip to content

Commit 8be6569

Browse files
Merge pull request #16 from thomvet/grow-cache-on-demand
Grow cache on demand
2 parents e4df007 + 2425941 commit 8be6569

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

test/core_resizing.jl

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
using Test, PreallocationTools, ForwardDiff
1+
using Test, PreallocationTools, ForwardDiff, LinearAlgebra
22

3+
4+
#test for downsizing cache
35
randmat = rand(5, 3)
46
sto = similar(randmat)
57
stod = dualcache(sto)
@@ -28,4 +30,26 @@ df2 = ForwardDiff.jacobian(x -> claytonsample!(stod, x[1], x[2]), [0.3; 0.0]) #s
2830
#because ForwardDiff flattens the output of jacobian, see: https://juliadiff.org/ForwardDiff.jl/stable/user/api/#ForwardDiff.jacobian
2931

3032
@test (length(randmat), 2) == size(df2)
31-
@test df1[1:5,2] df2[6:10,1]
33+
@test df1[1:5,2] df2[6:10,1]
34+
35+
#test for enlarging cache
36+
function rhs!(du, u, p, t)
37+
A = p
38+
mul!(du, A, u)
39+
end
40+
41+
function loss(du, u, p, t)
42+
_du = get_tmp(du, p)
43+
rhs!(_du, u, p, t)
44+
l = _du[1]
45+
return l
46+
end
47+
48+
u = [3.0, 0.0]
49+
A = ones(2,2)
50+
51+
du = similar(u)
52+
_du = dualcache(du)
53+
f = A -> loss(_du, u, A, 0.0)
54+
analyticalsolution = [3.0 0; 0 0]
55+
@test ForwardDiff.gradient(f, A) analyticalsolution

0 commit comments

Comments
 (0)