Skip to content

Commit 2420ea5

Browse files
author
Roger-luo
committed
add more tests & deprecation
1 parent 165afcd commit 2420ea5

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/FiniteDifferences.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ module FiniteDifferences
77
include("methods.jl")
88
include("numerics.jl")
99
include("grad.jl")
10+
11+
12+
@deprecate jacobian(fdm, f, x::Vector, D::Int) jacobian(fdm, f, x; len=D)
1013
end

test/grad.jl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)