create randperm and support pytorch backend (#10019)

This commit is contained in:
Park Jun
2025-04-24 20:29:02 +09:00
committed by GitHub
parent b545338e59
commit c3ad7b2a84
4 changed files with 25 additions and 1 deletions

View File

@@ -237,6 +237,13 @@ class TestTinygrad(unittest.TestCase):
b = random_fn(10,10).realize()
np.testing.assert_allclose(a.numpy(), b.numpy())
def test_randperm(self):
Tensor.manual_seed(0)
a = Tensor.randperm(10).realize()
np.testing.assert_equal(a.numpy(), [5, 2, 8, 1, 3, 7, 9, 6, 0, 4])
b = Tensor.randperm(1000).realize()
np.testing.assert_equal(set(b.numpy()), set(range(1000)))
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