@@ -194,10 +194,12 @@ Everything else is optional, and can be categorised into several groups:
194
194
Both absolute and relative tolerances can be specified using the `atol` and
195
195
`rtol` keyword arguments respectively. The behaviour of these is similar to
196
196
`isapprox()`, i.e. the value and gradient are considered correct if either
197
- atol or rtol is satisfied. The default values are `1e-8 ` for `atol` and
197
+ atol or rtol is satisfied. The default values are `100*eps() ` for `atol` and
198
198
`sqrt(eps())` for `rtol`.
199
199
200
- Note that gradients are always compared elementwise.
200
+ For the most part, it is the `rtol` check that is more meaningful, because
201
+ we cannot know the magnitude of logp and its gradient a priori. The `atol`
202
+ value is supplied to handle the case where gradients are equal to zero.
201
203
202
204
5. _Whether to output extra logging information._
203
205
@@ -218,7 +220,7 @@ function run_ad(
218
220
adtype:: AbstractADType ;
219
221
test:: Union{AbstractADCorrectnessTestSetting,Bool} = WithBackend (),
220
222
benchmark:: Bool = false ,
221
- atol:: AbstractFloat = 1e-8 ,
223
+ atol:: AbstractFloat = 100 * eps () ,
222
224
rtol:: AbstractFloat = sqrt (eps ()),
223
225
rng:: AbstractRNG = default_rng (),
224
226
varinfo:: AbstractVarInfo = link (VarInfo (rng, model), model),
@@ -264,9 +266,7 @@ function run_ad(
264
266
verbose && println (" expected : $((value_true, grad_true)) " )
265
267
exc () = throw (ADIncorrectException (value, value_true, grad, grad_true))
266
268
isapprox (value, value_true; atol= atol, rtol= rtol) || exc ()
267
- for (g, g_true) in zip (grad, grad_true)
268
- isapprox (g, g_true; atol= atol, rtol= rtol) || exc ()
269
- end
269
+ isapprox (grad, grad_true; atol= atol, rtol= rtol) || exc ()
270
270
end
271
271
272
272
# Benchmark
0 commit comments