@@ -45,9 +45,9 @@ Base.length(x::DummyType) = size(x.X, 1)
4545 end
4646
4747 @testset " multi vars jacobian/grad" begin
48- fdm = central_fdm (5 , 1 )
48+ rng, fdm = MersenneTwister ( 123456 ), central_fdm (5 , 1 )
4949 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 )
5151 jac_xs = jacobian (fdm, f1, x, y)
5252 @test jac_xs[1 ] ≈ jacobian (fdm, x-> f1 (x, y), x)
5353 @test jac_xs[2 ] ≈ jacobian (fdm, y-> f1 (x, y), y)
@@ -59,15 +59,26 @@ Base.length(x::DummyType) = size(x.X, 1)
5959 @test jac_xs[2 ] ≈ jacobian (fdm, y-> f1 (x, y), y)
6060
6161 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 )
6363 dxs = grad (fdm, f2, x, y)
6464 @test dxs[1 ] ≈ grad (fdm, x-> f2 (x, y), x)
6565 @test dxs[2 ] ≈ grad (fdm, y-> f2 (x, y), y)
6666
67- x, y = rand (3 , 3 ), 2
67+ x, y = rand (rng, 3 , 3 ), 2
6868 dxs = grad (fdm, f2, x, y)
6969 @test dxs[1 ] ≈ grad (fdm, x-> f2 (x, y), x)
7070 @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)
7182 end
7283
7384 function test_to_vec (x)
0 commit comments