Fix bug where Tensor.randn returns inf (#1192)

* fix randn inf bug

* add test

* more compact test

* clarify test purpose
This commit is contained in:
fluffy χατγιρλ
2023-07-08 21:03:46 +02:00
committed by GitHub
parent d9c1d81e99
commit 628ee46627
2 changed files with 8 additions and 1 deletions

View File

@@ -145,6 +145,13 @@ class TestTinygrad(unittest.TestCase):
b = random_fn(10,10).realize()
np.testing.assert_allclose(a.numpy(), b.numpy())
def test_randn_isnt_inf_on_zero(self):
# simulate failure case of rand handing a zero to randn
original_rand, Tensor.rand = Tensor.rand, Tensor.zeros
try: self.assertNotIn(np.inf, Tensor.randn(16).numpy())
except: raise
finally: Tensor.rand = original_rand
def test_zeros_like_has_same_dtype(self):
for datatype in [dtypes.float16, dtypes.float32, dtypes.int8, dtypes.int32, dtypes.int64, dtypes.uint8]:
a = Tensor([1, 2, 3], dtype=datatype)