Skip to content

Commit 596ea66

Browse files
committed
added helpful failure massages for tests
1 parent 49a0324 commit 596ea66

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/testers.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ function test_rrule(
213213
res === nothing && throw(MethodError(rrule_f, Tuple{Core.Typeof.(primals)...}))
214214
y_ad, pullback = res
215215
y = call(primals...)
216-
test_approx(y_ad, y; isapprox_kwargs...) # make sure primal is correct
216+
test_approx(y_ad, y, "Failed primal value check"; isapprox_kwargs...) # make sure primal is correct
217217

218218
ȳ = output_tangent isa Auto ? rand_tangent(y) : output_tangent
219219

@@ -231,7 +231,8 @@ function test_rrule(
231231
# Correctness testing via finite differencing.
232232
is_ignored = isa.(accum_cotangents, NoTangent)
233233
fd_cotangents = _make_j′vp_call(fdm, call, ȳ, primals, is_ignored)
234-
foreach(accum_cotangents, ad_cotangents, fd_cotangents) do args...
234+
msgs = ntuple(i->"cotangent for input $i, $(summary(fd_cotangents[i]))", length(fd_cotangents))
235+
foreach(accum_cotangents, ad_cotangents, fd_cotangents, msgs) do args...
235236
_test_cotangent(args...; check_inferred=check_inferred, isapprox_kwargs...)
236237
end
237238

@@ -298,14 +299,15 @@ If `accum_cotangent` is `NoTangent()`, i.e., the argument was marked as non-diff
298299
function _test_cotangent(
299300
accum_cotangent,
300301
ad_cotangent,
301-
fd_cotangent;
302+
fd_cotangent,
303+
msg="";
302304
check_inferred=true,
303305
kwargs...,
304306
)
305307
ad_cotangent isa AbstractThunk && check_inferred && _test_inferred(unthunk, ad_cotangent)
306308

307309
# The main test of the actual derivative being correct:
308-
test_approx(ad_cotangent, fd_cotangent; kwargs...)
310+
test_approx(ad_cotangent, fd_cotangent, msg; kwargs...)
309311
_test_add!!_behaviour(accum_cotangent, ad_cotangent; kwargs...)
310312
end
311313

0 commit comments

Comments
 (0)