Skip to content

Commit

Permalink
test masked assign views (#4599)
Browse files Browse the repository at this point in the history
* possible masked

* not contiguous mask
  • Loading branch information
Qazalin committed May 15, 2024
1 parent ff64bca commit a4a23c4
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/test_assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,22 @@ def test_permuted_reduceop_multioutput_dual_use_possible(self):
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")
Expand Down

0 comments on commit a4a23c4

Please sign in to comment.