create Tensor from bytes without numpy (#4964)

This commit is contained in:
chenyu
2024-06-14 13:37:27 -04:00
committed by GitHub
parent 5eee974b2a
commit dae1c8abe2
2 changed files with 15 additions and 5 deletions

View File

@@ -300,6 +300,13 @@ class TestTinygrad(unittest.TestCase):
data = _generate_data(depth)
np.testing.assert_allclose(Tensor(data).numpy(), np.array(data))
def test_tensor_bytes(self):
data = b"abc123"
t = Tensor(data)
assert t.dtype == dtypes.uint8
assert t.shape == (6,)
np.testing.assert_equal(t.numpy(), list(data))
def test_tensor_copy(self):
x = copy.deepcopy(Tensor.ones((3,3,3)))
np.testing.assert_allclose(x.numpy(), np.ones((3,3,3)))