fix pad 0 size (#3277)

* fix pad 0 size

* put in view, not pad

* test was wrong
This commit is contained in:
George Hotz
2024-01-30 08:58:10 -08:00
committed by GitHub
parent b0a755288f
commit 6a4a5dc79d
3 changed files with 4 additions and 14 deletions
+2 -1
View File
@@ -996,7 +996,8 @@ class TestIndexing(unittest.TestCase):
z = y[:, 1:1, :]
numpy_testing_assert_equal_helper((2, 0, 4), z.shape)
# this isn't technically necessary, but matches NumPy stride calculations.
numpy_testing_assert_equal_helper((60, 20, 5), z.lazydata.st.real_strides())
# NOTE: this is empty and shouldn't have strides
#numpy_testing_assert_equal_helper((60, 20, 5), z.lazydata.st.real_strides())
# NOTE tinygrad's int slicing implementation makes this not contiguous
# self.assertTrue(z.lazydata.st.contiguous)
+1 -13
View File
@@ -2,7 +2,6 @@
import numpy as np
import unittest
from tinygrad import Tensor, Device, dtypes
from tinygrad.device import Interpreted
class TestLazyBuffer(unittest.TestCase):
def test_fromcpu_shape_tracker(self):
@@ -56,18 +55,7 @@ class TestLazyBuffer(unittest.TestCase):
a = Tensor.zeros(4,4,4).shrink((None, (0,0), None)).cast(dtypes.int32)
b = Tensor.zeros(4,1,4)
c = a.cat(b, dim=1)
if isinstance(Device[Device.DEFAULT], Interpreted):
# TODO: fix cast resets shapetracker and remove this block
# this is expectedFailure with a condition
try:
np.testing.assert_allclose(c.numpy(), np.concatenate((a.numpy(), b.numpy()), axis=1))
except Exception:
pass
else:
raise ValueError("assert_allclose not failed")
else:
np.testing.assert_allclose(c.numpy(), np.concatenate((a.numpy(), b.numpy()), axis=1))
np.testing.assert_allclose(c.numpy(), np.concatenate((a.numpy(), b.numpy()), axis=1))
if __name__ == "__main__":
unittest.main()
+1
View File
@@ -138,6 +138,7 @@ class LazyBuffer:
# *** movement ops ***
def _view(self, new_st:ShapeTracker) -> LazyBuffer:
if self.st.size == 0: return self.const(0, new_st.shape)
if new_st.contiguous and self.base.shape == new_st.shape: return self.base
return create_lazybuffer(self.device, new_st, self.dtype, base=self.base)