Commit 376855d5 authored by Jonathan Tow's avatar Jonathan Tow
Browse files

Loosen tolerances that were intended for `float64` values

parent 377a4fe2
......@@ -16,7 +16,11 @@ def assert_target(name, ob):
fname = f"tests/testdata/{name}.json"
if os.path.exists(fname):
with open(fname) as fh:
assert flatten(json.load(fh)) == pytest.approx(flatten(json.loads(json.dumps(ob, sort_keys=True))))
# Use relative tolerance of 1e-5 and absolute tolerance of 1e-8
# assuming most metrics work on `float32` values, which is the common
# default floating type across popular libraries (PyTorch, Tensorflow, and JAX).
assert flatten(json.load(fh)) == pytest.approx(
flatten(json.loads(json.dumps(ob, sort_keys=True))), rel=1e-5, abs=1e-8)
else:
with open(fname, 'w') as fh:
json.dump(ob, fh, sort_keys=True)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment