diff --git a/test/test_tensor.py b/test/test_tensor.py index 2e36938a17..c1907d7130 100644 --- a/test/test_tensor.py +++ b/test/test_tensor.py @@ -424,6 +424,10 @@ class TestTinygrad(unittest.TestCase): data = [np.array(1.0), np.array(2.0), np.array(3.0)] np.testing.assert_equal(Tensor(data).numpy(), np.array(data)) + def test_tensor_dtype_errors(self): + with self.assertRaises(AttributeError): Tensor([3], dtype="typo") + with self.assertRaises(TypeError): Tensor([3], dtype=(dtypes.int,)) + def test_tensor_bytes(self): data = b"abc123" t = Tensor(data) diff --git a/tinygrad/tensor.py b/tinygrad/tensor.py index 22f1fa68b7..04520c9c19 100644 --- a/tinygrad/tensor.py +++ b/tinygrad/tensor.py @@ -125,7 +125,6 @@ class Tensor(SimpleMathTrait): def __init__(self, data:Union[None, ConstType, bytes, List, Tuple, UOp, MultiLazyBuffer, 'np.ndarray', pathlib.Path], # type: ignore [name-defined] # noqa: F821 device:Optional[Union[str, tuple, list]]=None, dtype:Optional[DTypeLike]=None, requires_grad:Optional[bool]=None): if dtype is not None: dtype = to_dtype(dtype) - assert dtype is None or isinstance(dtype, DType), f"invalid dtype {dtype}" if device is None and isinstance(data, pathlib.Path): device = f"DISK:{data.resolve()}" # keep it on the disk if device is None device = tuple(Device.canonicalize(x) for x in device) if isinstance(device, (tuple, list)) else Device.canonicalize(device)