Skip to content

Commit

Permalink
better approx equality test failure reporting, fix potential zero div…
Browse files Browse the repository at this point in the history
…isor breakage
  • Loading branch information
jrevels committed Aug 6, 2015
1 parent 3fd8f4c commit 1c4f842
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
16 changes: 10 additions & 6 deletions test/test_hessnum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ using ForwardDiff:
isconstant,
gradnum

floatrange = 0.0:.01:.99
intrange = 0:10
floatrange = .01:.01:.99
intrange = 1:10
N = 4
T = Float64
C = NTuple{N,T}
Expand Down Expand Up @@ -154,9 +154,13 @@ rand_hess = HessianNum(rand_grad, rand_hessvec)
#-------------------------#
function hess_approx_eq(a::HessianNum, b::HessianNum)
eps = 1e-10
@test_approx_eq_eps value(a) value(b) eps
@test_approx_eq_eps collect(grad(a)) collect(grad(b)) eps
@test_approx_eq_eps hess(a) hess(b) eps
try
@test_approx_eq_eps value(a) value(b) eps
@test_approx_eq_eps collect(grad(a)) collect(grad(b)) eps
@test_approx_eq_eps hess(a) hess(b) eps
catch err
error("Failure: HessianNum a and HessianNum b should be equal.\n Error: $err\n rand_hess = $rand_hess\n test_hess = $test_hess")
end
end

@test gradnum(rand_hess * test_hess) == rand_grad * test_grad
Expand Down Expand Up @@ -210,7 +214,7 @@ function hess_test_result(f_expr, x::Vector)
end

function hess_test_x(fsym, N)
randrange = 0.01:.01:.99
randrange = .01:.01:.99

needs_modification = (:acosh, :acoth)
if fsym in needs_modification
Expand Down
18 changes: 11 additions & 7 deletions test/test_tensnum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ using ForwardDiff:
hessnum,
t_inds_2_h_ind

floatrange = 0.0:.01:.99
intrange = 0:10
floatrange = .01:.01:.99
intrange = 1:10
N = 4
T = Float64
C = NTuple{N,T}
Expand Down Expand Up @@ -171,10 +171,14 @@ rand_tens = TensorNum(rand_hess, rand_tensvec)
#-------------------------#
function tens_approx_eq(a::TensorNum, b::TensorNum)
eps = 1e-10
@test_approx_eq_eps value(a) value(b) eps
@test_approx_eq_eps collect(grad(a)) collect(grad(b)) eps
@test_approx_eq_eps hess(a) hess(b) eps
@test_approx_eq_eps tens(a) tens(b) eps
try
@test_approx_eq_eps value(a) value(b) eps
@test_approx_eq_eps collect(grad(a)) collect(grad(b)) eps
@test_approx_eq_eps hess(a) hess(b) eps
@test_approx_eq_eps tens(a) tens(b) eps
catch err
error("Failure: TensorNum a and TensorNum b should be equal.\n Error: $err\n rand_tens = $rand_tens\n test_tens = $test_tens")
end
end

@test hessnum(rand_tens * test_tens) == rand_hess * test_hess
Expand Down Expand Up @@ -229,7 +233,7 @@ function tens_test_result(f_expr, x::Vector)
end

function tens_test_x(fsym, N)
randrange = 0.01:.01:.99
randrange = .01:.01:.99

needs_modification = tuple(:acosh, :acoth)
if fsym in needs_modification
Expand Down

0 comments on commit 1c4f842

Please sign in to comment.