Skip to content

Commit 8692270

Browse files
authored
Add assertNotAllClose to TestCase. (#80)
1 parent 47f8fbc commit 8692270

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

keras_rs/src/testing/test_case.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,32 @@ def assertAllClose(
4242
actual, desired, atol=atol, rtol=rtol, err_msg=msg
4343
)
4444

45+
def assertNotAllClose(
46+
self,
47+
actual: types.Tensor,
48+
desired: types.Tensor,
49+
atol: float = 1e-6,
50+
rtol: float = 1e-6,
51+
msg: str = "",
52+
) -> None:
53+
"""Verify that not all elements of two tensors are close in value.
54+
55+
Args:
56+
actual: Actual tensor, the first tensor to compare.
57+
desired: Expected tensor, the second tensor to compare.
58+
atol: Absolute tolerance.
59+
rtol: Relative tolerance.
60+
msg: Optional error message.
61+
"""
62+
try:
63+
self.assertAllClose(actual, desired, atol=atol, rtol=rtol, msg=msg)
64+
except AssertionError:
65+
return
66+
raise AssertionError(
67+
f"The two values are close at all elements.\n{msg}.\n"
68+
f"Values: {actual}"
69+
)
70+
4571
def assertAllEqual(
4672
self, actual: types.Tensor, desired: types.Tensor, msg: str = ""
4773
) -> None:

0 commit comments

Comments
 (0)