@@ -45,9 +45,9 @@ Base.length(x::DummyType) = size(x.X, 1)
45
45
end
46
46
47
47
@testset " multi vars jacobian/grad" begin
48
- fdm = central_fdm (5 , 1 )
48
+ rng, fdm = MersenneTwister ( 123456 ), central_fdm (5 , 1 )
49
49
f1 (x, y) = x * y + x
50
- x, y = rand (3 , 3 ), rand (3 , 3 )
50
+ x, y = rand (rng, 3 , 3 ), rand (rng, 3 , 3 )
51
51
jac_xs = jacobian (fdm, f1, x, y)
52
52
@test jac_xs[1 ] ≈ jacobian (fdm, x-> f1 (x, y), x)
53
53
@test jac_xs[2 ] ≈ jacobian (fdm, y-> f1 (x, y), y)
@@ -59,15 +59,26 @@ Base.length(x::DummyType) = size(x.X, 1)
59
59
@test jac_xs[2 ] ≈ jacobian (fdm, y-> f1 (x, y), y)
60
60
61
61
f2 (x, y) = sum (x * y + x)
62
- x, y = rand (3 , 3 ), rand (3 , 3 )
62
+ x, y = rand (rng, 3 , 3 ), rand (rng, 3 , 3 )
63
63
dxs = grad (fdm, f2, x, y)
64
64
@test dxs[1 ] ≈ grad (fdm, x-> f2 (x, y), x)
65
65
@test dxs[2 ] ≈ grad (fdm, y-> f2 (x, y), y)
66
66
67
- x, y = rand (3 , 3 ), 2
67
+ x, y = rand (rng, 3 , 3 ), 2
68
68
dxs = grad (fdm, f2, x, y)
69
69
@test dxs[1 ] ≈ grad (fdm, x-> f2 (x, y), x)
70
70
@test dxs[2 ] ≈ grad (fdm, y-> f2 (x, y), y)
71
+
72
+ f3 (x:: Tuple ) = sum (x[1 ]) + x[2 ]
73
+ dxs = grad (fdm, f3, (x, y))
74
+ @test dxs[1 ] ≈ grad (fdm, x-> f3 ((x, y)), x)
75
+ @test dxs[2 ] ≈ grad (fdm, y-> f3 ((x, y)), y)
76
+
77
+ f4 (d:: Dict ) = sum (d[:x ]) + d[:y ]
78
+ d = Dict (:x => x, :y => y)
79
+ dxs = grad (fdm, f4, d)
80
+ @test dxs[:x ] ≈ grad (fdm, x-> f3 ((x, y)), x)
81
+ @test dxs[:y ] ≈ grad (fdm, y-> f3 ((x, y)), y)
71
82
end
72
83
73
84
function test_to_vec (x)
0 commit comments