test case to show clang and python doing math in double (#3628)

This commit is contained in:
chenyu 2024-03-06 13:49:03 -05:00 committed by GitHub
parent 568353fa84
commit bc2a13a5f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 21 additions and 0 deletions

View File

@ -530,5 +530,26 @@ class TestAutoCastType(unittest.TestCase):
assert (Tensor([1, 2], dtype=dtypes.float16) / 2).dtype == dtypes.float16
assert (Tensor([1, 2], dtype=dtypes.float16) / 2.0).dtype == dtypes.float16
class TestImplicitFunctionTypeChange(unittest.TestCase):
def test_functions(self):
result = []
for func in [
lambda t: t.exp(),
lambda t: t.exp2(),
lambda t: t.log(),
lambda t: t.log2(),
lambda t: t.sqrt(),
lambda t: t.sin(),
]:
t = func(Tensor([4.0, 3.0])).max() == func(Tensor([4.0, 3.0]))
result.append(t.numpy().sum())
if Device.DEFAULT not in ["PYTHON", "CLANG"]:
assert all(result)
else:
# CLANG and PYTHON function default returns in double, and comparison to float can fail
# TODO: fix this
assert not all(result)
if __name__ == '__main__':
unittest.main()