diff --git a/test/test_tensor.py b/test/test_tensor.py index 0e9c20d022..d73e55e36a 100644 --- a/test/test_tensor.py +++ b/test/test_tensor.py @@ -652,19 +652,26 @@ class TestZeroShapeTensor(unittest.TestCase): def test_clone(self): a = Tensor.rand(16, 16).realize() - self.assertIsNot(a.lazydata, a.clone().lazydata) - np.testing.assert_allclose(a.numpy(), a.clone().numpy()) + b = a.clone() + np.testing.assert_allclose(a.numpy(), b.numpy()) + self.assertIsNot(a.lazydata.base.buffer, b.lazydata.base.buffer) a = Tensor.rand(16, 16).mul(5.0).add(5.0) - self.assertIsNot(a.lazydata, a.clone().lazydata) - np.testing.assert_allclose(a.numpy(), a.clone().numpy()) + b = a.clone() + np.testing.assert_allclose(a.numpy(), b.numpy()) + self.assertIsNot(a.lazydata.base.buffer, b.lazydata.base.buffer) def test_clone_with_shrink(self): - a = Tensor.empty(16, 16) - self.assertIsNot(a.lazydata, a.clone().lazydata) + a = Tensor.rand(16, 16) + b = a.shrink(((2, 10), None)).clone() + b.realize() + self.assertIsNot(a.lazydata.base.buffer, b.lazydata.base.buffer) - b = a.shrink(((2, 10), None)) - self.assertIsNot(b.lazydata, b.clone().lazydata) + def test_clone_with_shrink_realized(self): + a = Tensor.rand(16, 16).realize() + b = a.shrink(((2, 10), None)).clone() + b.realize() + self.assertIsNot(a.lazydata.base.buffer, b.lazydata.base.buffer) def test_clone_with_grad(self): a = Tensor.rand(16, 16, requires_grad=True)