Skip to content

Commit 6d2be82

Browse files
authored
Reformat rrule_test for more informative output on failure (#27)
Currently, if the check for all rules comparing approximately equal to their finite differencing counterparts fails, the test failure just tells you that `all(...)` was `false`. If we restructure it as a loop over the results, a failure will display the actual values that were compared, which is much more informative. While I was in here, I also changed the `map` directly below to a loop, since that's what the `map` was doing; the resulting vector of `nothing`s was not being used. It could just have well have been a `foreach`, but an explicit loop seems clearer.
1 parent c5fd246 commit 6d2be82

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

test/test_util.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ function rrule_test(f, ȳ, xx̄s::Tuple{Any, Any}...; rtol=1e-9, atol=1e-9, fdm
5757
@test f(xs...) == Ω
5858

5959
# Correctness testing via finite differencing.
60-
Δxs_ad, Δxs_fd = map(Δx_rule->Δx_rule(ȳ), Δx_rules), j′vp(fdm, f, ȳ, xs...)
61-
@test all(zip(Δxs_ad, Δxs_fd)) do (Δx_ad, Δx_fd)
62-
isapprox(Δx_ad, Δx_fd; rtol=rtol, atol=atol, kwargs...)
60+
Δxs_ad = map(Δx_rule->Δx_rule(ȳ), Δx_rules)
61+
Δxs_fd = j′vp(fdm, f, ȳ, xs...)
62+
for (Δx_ad, Δx_fd) in zip(Δxs_ad, Δxs_fd)
63+
@test isapprox(Δx_ad, Δx_fd; rtol=rtol, atol=atol, kwargs...)
6364
end
6465

6566
# Assuming the above to be correct, check that other ChainRules mechanisms are correct.
66-
map(x̄s, Δx_rules, Δxs_ad) do x̄, Δx_rule, Δx_ad
67+
for (x̄, Δx_rule, Δx_ad) in zip(x̄s, Δx_rules, Δxs_ad)
6768
test_accumulation(x̄, Δx_rule, ȳ, Δx_ad)
6869
test_accumulation(Zero(), Δx_rule, ȳ, Δx_ad)
69-
return nothing
7070
end
7171
end
7272

0 commit comments

Comments
 (0)