提交 3ced044b authored 作者: Ricardo Vieira's avatar Ricardo Vieira 提交者: Ricardo Vieira

Tweak test tolerances

上级 856b81b9
...@@ -31,7 +31,7 @@ def test_convolve1d(mode, data_shape, kernel_shape): ...@@ -31,7 +31,7 @@ def test_convolve1d(mode, data_shape, kernel_shape):
np.testing.assert_allclose( np.testing.assert_allclose(
fn(data_val, kernel_val), fn(data_val, kernel_val),
scipy_convolve(data_val, kernel_val, mode=mode), scipy_convolve(data_val, kernel_val, mode=mode),
rtol=1e-6 if config.floatX == "float32" else 1e-15, rtol=1e-6 if config.floatX == "float32" else 1e-14,
) )
utt.verify_grad(op=lambda x: op(x, kernel_val), pt=[data_val]) utt.verify_grad(op=lambda x: op(x, kernel_val), pt=[data_val])
...@@ -198,17 +198,18 @@ def test_batched_1d_agrees_with_2d_row_filter(mode, method): ...@@ -198,17 +198,18 @@ def test_batched_1d_agrees_with_2d_row_filter(mode, method):
fn = function([data, kernel_1d], [output_1d, output_2d, grad_1d, grad_2d]) fn = function([data, kernel_1d], [output_1d, output_2d, grad_1d, grad_2d])
data_val = np.random.normal(size=(10, 8)).astype(config.floatX) rng = np.random.default_rng([201, sum(map(ord, mode)), sum(map(ord, method))])
kernel_1d_val = np.random.normal(size=(3,)).astype(config.floatX) data_val = rng.normal(size=(10, 8)).astype(config.floatX)
kernel_1d_val = rng.normal(size=(3,)).astype(config.floatX)
forward_1d, forward_2d, backward_1d, backward_2d = fn(data_val, kernel_1d_val) forward_1d, forward_2d, backward_1d, backward_2d = fn(data_val, kernel_1d_val)
np.testing.assert_allclose( np.testing.assert_allclose(
forward_1d, forward_1d,
forward_2d, forward_2d,
rtol=1e-5 if config.floatX == "float32" else 1e-13, rtol=1e-5 if config.floatX == "float32" else 1e-12,
) )
np.testing.assert_allclose( np.testing.assert_allclose(
backward_1d, backward_1d,
backward_2d, backward_2d,
rtol=1e-5 if config.floatX == "float32" else 1e-13, rtol=1e-5 if config.floatX == "float32" else 1e-12,
) )
...@@ -2584,7 +2584,7 @@ class TestARange: ...@@ -2584,7 +2584,7 @@ class TestARange:
start_v_, stop_v_, step_v_, dtype=out.dtype start_v_, stop_v_, step_v_, dtype=out.dtype
) )
assert np.all(f_val == expected_val) np.testing.assert_allclose(f_val, expected_val, strict=True, rtol=3e-7)
@pytest.mark.parametrize( @pytest.mark.parametrize(
"cast_policy", "cast_policy",
...@@ -2621,7 +2621,7 @@ class TestARange: ...@@ -2621,7 +2621,7 @@ class TestARange:
elif config.cast_policy == "numpy+floatX": elif config.cast_policy == "numpy+floatX":
expected_val = np.arange(start_v_, stop_v_, step_v_) expected_val = np.arange(start_v_, stop_v_, step_v_)
assert np.all(f_val == expected_val) np.testing.assert_allclose(f_val, expected_val, strict=True)
@pytest.mark.parametrize( @pytest.mark.parametrize(
"cast_policy", "cast_policy",
......
...@@ -432,7 +432,7 @@ class BlockwiseOpTester: ...@@ -432,7 +432,7 @@ class BlockwiseOpTester:
pt_out, pt_out,
np_out, np_out,
rtol=1e-7 if config.floatX == "float64" else 1e-5, rtol=1e-7 if config.floatX == "float64" else 1e-5,
atol=1e-6 if config.floatX == "float64" else 1e-4, atol=1e-6 if config.floatX == "float64" else 2e-2,
) )
......
...@@ -166,8 +166,9 @@ class TestSvd(utt.InferShapeTester): ...@@ -166,8 +166,9 @@ class TestSvd(utt.InferShapeTester):
np_outputs = np_outputs if isinstance(np_outputs, tuple) else [np_outputs] np_outputs = np_outputs if isinstance(np_outputs, tuple) else [np_outputs]
rtol = 1e-5 if config.floatX == "float32" else 1e-7
for np_val, pt_val in zip(np_outputs, pt_outputs, strict=True): for np_val, pt_val in zip(np_outputs, pt_outputs, strict=True):
assert _allclose(np_val, pt_val) np.testing.assert_allclose(np_val, pt_val, rtol=rtol)
def test_svd_infer_shape(self): def test_svd_infer_shape(self):
self.validate_shape((4, 4), full_matrices=True, compute_uv=True) self.validate_shape((4, 4), full_matrices=True, compute_uv=True)
...@@ -465,15 +466,20 @@ class TestEigh(TestEig): ...@@ -465,15 +466,20 @@ class TestEigh(TestEig):
w_np, v_np = np.linalg.eigh(A_val) w_np, v_np = np.linalg.eigh(A_val)
np.testing.assert_allclose(w, w_np) np.testing.assert_allclose(w, w_np)
np.testing.assert_allclose(v, v_np) np.testing.assert_allclose(v, v_np)
assert_array_almost_equal(np.dot(A_val, v), w * v) rtol = 1e-2 if self.dtype == "float32" else 1e-7
np.testing.assert_allclose(np.dot(A_val, v), w * v, rtol=rtol)
def test_uplo(self): def test_uplo(self):
S = self.S S = self.S
a = matrix(dtype=self.dtype) a = matrix(dtype=self.dtype)
wu, vu = (out.eval({a: S}) for out in self.op(a, "U")) wu, vu = (out.eval({a: S}) for out in self.op(a, "U"))
wl, vl = (out.eval({a: S}) for out in self.op(a, "L")) wl, vl = (out.eval({a: S}) for out in self.op(a, "L"))
assert_array_almost_equal(wu, wl) atol = 1e-14 if np.dtype(self.dtype).itemsize == 8 else 1e-5
assert_array_almost_equal(vu * np.sign(vu[0, :]), vl * np.sign(vl[0, :])) rtol = 1e-14 if np.dtype(self.dtype).itemsize == 8 else 1e-3
np.testing.assert_allclose(wu, wl, atol=atol, rtol=rtol)
np.testing.assert_allclose(
vu * np.sign(vu[0, :]), vl * np.sign(vl[0, :]), atol=atol, rtol=rtol
)
def test_grad(self): def test_grad(self):
X = self.X X = self.X
......
...@@ -886,7 +886,7 @@ def test_expm(): ...@@ -886,7 +886,7 @@ def test_expm():
"mode", ["symmetric", "nonsymmetric_real_eig", "nonsymmetric_complex_eig"][-1:] "mode", ["symmetric", "nonsymmetric_real_eig", "nonsymmetric_complex_eig"][-1:]
) )
def test_expm_grad(mode): def test_expm_grad(mode):
rng = np.random.default_rng() rng = np.random.default_rng([898, sum(map(ord, mode))])
match mode: match mode:
case "symmetric": case "symmetric":
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论