From a4a23c40a0c3ceecda65bcb671d8cb6c73baf9fb Mon Sep 17 00:00:00 2001 From: qazal <77887910+Qazalin@users.noreply.github.com> Date: Wed, 15 May 2024 20:06:48 +0800 Subject: [PATCH] test masked assign views (#4599) * possible masked * not contiguous mask --- test/test_assign.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/test_assign.py b/test/test_assign.py index c18d6301cf..6027233982 100644 --- a/test/test_assign.py +++ b/test/test_assign.py @@ -345,6 +345,22 @@ class TestAssign(unittest.TestCase): np.testing.assert_equal(b.numpy(), a.numpy().sum(1) + np.arange(32 * 32).reshape(32, 32)) np.testing.assert_equal(c.numpy(), a.numpy().sum(1) + np.arange(32 * 32).reshape(32, 32).transpose(1, 0)) + def test_permuted_assignment_masked_view_possible(self): + a = Tensor.ones(4, 4).contiguous().realize() + b = a.shrink((None, (0, 2))).pad((None, (0, 2)), 2) + a.assign(a + b) + kc = GlobalCounters.kernel_count + a.realize() + assert GlobalCounters.kernel_count - kc == 1 + np.testing.assert_equal(a.numpy(), np.ones((4, 4))+np.pad(np.ones((4, 4))[:, 0:2], ((0, 0), (0, 2)), constant_values=2)) + + def test_permuted_assignment_masked_view_not_contiguous(self): + a = Tensor.ones(4, 4).contiguous().realize() + with self.assertRaisesRegex(RuntimeError, "contiguous"): + b = a.shrink((None, (0, 2))).pad((None, (0, 2)), 2).permute(1, 0) + a.assign(a + b) + a.realize() + # TODO: is there a way to sneak in a permute such that it returns the wrong answer? @unittest.skip("don't use output buffer, and mismatch dtype no longer supported")