Skip to content

Commit 0eb5a71

Browse files
author
Roger-luo
committed
add test to grad
1 parent c43f01e commit 0eb5a71

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

test/grad.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Base.length(x::DummyType) = size(x.X, 1)
4444
@test Ac == A
4545
end
4646

47-
@testset "multi vars jacobian" begin
47+
@testset "multi vars jacobian/grad" begin
4848
fdm = central_fdm(5, 1)
4949
f1(x, y) = x * y + x
5050
x, y = rand(3, 3), rand(3, 3)
@@ -57,6 +57,17 @@ Base.length(x::DummyType) = size(x.X, 1)
5757
jac_xs = jacobian(fdm, f1, x, y)
5858
@test jac_xs[1] jacobian(fdm, x->f1(x, y), x)
5959
@test jac_xs[2] jacobian(fdm, y->f1(x, y), y)
60+
61+
f2(x, y) = sum(x * y + x)
62+
x, y = rand(3, 3), rand(3, 3)
63+
dxs = grad(fdm, f2, x, y)
64+
@test dxs[1] grad(fdm, x->f2(x, y), x)
65+
@test dxs[2] grad(fdm, y->f2(x, y), y)
66+
67+
x, y = rand(3, 3), 2
68+
dxs = grad(fdm, f2, x, y)
69+
@test dxs[1] grad(fdm, x->f2(x, y), x)
70+
@test dxs[2] grad(fdm, y->f2(x, y), y)
6071
end
6172

6273
function test_to_vec(x)

0 commit comments

Comments
 (0)