canonicalize 0 in shape in View.create (#4815)

set strides to 0, offset to 0, mask to None, and contiguous to True with size 0 view.
This commit is contained in:
chenyu
2024-06-03 13:37:37 -04:00
committed by GitHub
parent d064bf6d8c
commit 45083ccb43
2 changed files with 5 additions and 3 deletions

View File

@@ -379,17 +379,17 @@ class TestZeroShapeTensor(unittest.TestCase):
t = Tensor.empty(3, 2, 0)
assert t.shape == (3, 2, 0)
# numpy has stride 0, 0, 0; torch has stride 2, 1, 1
assert t.lazydata.st.real_strides() == (0, 0, 1)
assert t.lazydata.st.real_strides() == (0, 0, 0)
t = Tensor.empty(3, 0, 2)
assert t.shape == (3, 0, 2)
# numpy has stride 0, 0, 0; torch has stride 2, 2, 1
assert t.lazydata.st.real_strides() == (0, 2, 1)
assert t.lazydata.st.real_strides() == (0, 0, 0)
t = Tensor.empty(0, 0, 0)
assert t.shape == (0, 0, 0)
# numpy has stride 0, 0, 0; torch has stride 1, 1, 1
assert t.lazydata.st.real_strides() == (0, 0, 1)
assert t.lazydata.st.real_strides() == (0, 0, 0)
def test_rand(self):
t = Tensor.rand(3, 2, 0)