test slice assign twice retains the buffer (#14807)

This commit is contained in:
chenyu
2026-02-16 20:01:47 -05:00
committed by GitHub
parent ba39a19114
commit 5bca5be2d2

View File

@@ -55,6 +55,24 @@ class TestAssign(unittest.TestCase):
with self.assertRaises(AssertionError):
assert x.uop.base.realized is buf
def test_assign_slice_add(self):
x = Tensor([0, 0]).realize()
buf = x.uop.base.realized
x[0] += 1
x.realize()
assert x.tolist() == [1, 0]
assert x.uop.base.realized is buf
def test_assign_slice_add_twice(self):
# NOTE: this has two kernels
x = Tensor([0, 0]).realize()
buf = x.uop.base.realized
x[0] += 1
x[0] += 1
x.realize()
assert x.tolist() == [2, 0]
assert x.uop.base.realized is buf
def test_assign_add_double(self):
def f(x):
x += 1