From ea9d4e6d7836634934232fc27266452052079b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Jargut?= <74570458+dee7ine@users.noreply.github.com> Date: Thu, 1 Jun 2023 22:10:08 +0200 Subject: [PATCH] Slightly improved readability of reshape method condition check (#898) * Added few missing return typehints for tensor.py * added test for empty tensor for Tensor.numel() * fixed missing numel call in test_numel * small change in reshape shape condition check * Merge from upstream --- tinygrad/tensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tinygrad/tensor.py b/tinygrad/tensor.py index c3058875d1..ac5cd2de92 100644 --- a/tinygrad/tensor.py +++ b/tinygrad/tensor.py @@ -224,7 +224,7 @@ class Tensor: def reshape(self, shape, *args) -> Tensor: new_shape = argfix(shape, *args) - assert all(x != 0 for x in new_shape), f"zeros not allowed in shape {new_shape}" + assert 0 not in new_shape, f"zeros not allowed in shape {new_shape}" return mlops.Reshape.apply(self, shape=tuple(-prod(self.shape) // prod(new_shape) if s == -1 else s for s in new_shape)) def expand(self, shape, *args) -> Tensor: return mlops.Expand.apply(self, shape=tuple(x if x != -1 else s for s,x in zip(self.shape, argfix(shape, *args)))) def permute(self, order, *args) -> Tensor: return mlops.Permute.apply(self, order=argfix(order, *args))