ban __bool__ on Tensor (#3632)

* ban __bool__ on Tensor

avoid misuse

* test case

* fix tests

* fix more tests
This commit is contained in:
chenyu
2024-03-06 17:12:35 -05:00
committed by GitHub
parent 81baf3eed3
commit 8f10bfa2ff
7 changed files with 19 additions and 7 deletions

View File

@@ -326,6 +326,14 @@ class TestTinygrad(unittest.TestCase):
assert type(reshaped_item) == type(a), a
np.testing.assert_allclose(reshaped_item, a), a
def test_no_bool(self):
with self.assertRaises(TypeError):
if Tensor(["3"]):
print("hi")
with self.assertRaises(TypeError):
_a = Tensor([3]) in [Tensor([3]), Tensor([4]), Tensor([5])]
@unittest.skipIf(CI and Device.DEFAULT in {"GPU", "CUDA", "METAL"}, "no GPU CI")
class TestMoveTensor(unittest.TestCase):
d0, d1 = f"{Device.DEFAULT}:0", f"{Device.DEFAULT}:1"