perf: assert behind if is not optimized (#1847)

* perf: assert behind if is not optimized

* Update helpers.py

---------

Co-authored-by: Roelof van Dijk <[email protected]>
Co-authored-by: George Hotz <[email protected]>
This commit is contained in:
Roelof van Dijk
2023-09-29 11:07:24 -07:00
committed by GitHub
co-authored by Roelof van Dijk George Hotz
parent 8e9db88474
commit e7a49e84c8
+1 -2
View File
@@ -89,8 +89,7 @@ class View:
assert all(is_sym_int(x) and x > 0 for x in new_shape), f"shape must be symbolic ints and can't contain 0 or negative numbers {new_shape}"
# only check size for int shapes. we don't check symbolic here as long as the reshape itself can be done
if all_int(self.shape) and all_int(new_shape):
assert prod(self.shape) == prod(new_shape), f"can't reshape {self.shape} -> {new_shape}"
assert prod(self.shape) == prod(new_shape) if all_int(self.shape + new_shape) else True, f"can't reshape {self.shape=} -> {new_shape=}"
# after the asserts, it's okay to check contiguous
if self.contiguous: return View.create(new_shape)