From ced886f26cbcc1a79e10fa6af2d9b30b590cf030 Mon Sep 17 00:00:00 2001 From: chenyu Date: Sat, 31 Jan 2026 14:26:47 -0500 Subject: [PATCH] failed test case for assign into bitcast (#14469) * failed test case for assign into bitcast DISK assign has custom hack for this. need to fix before we can unify assign * test_assign_bitcast_different_size --- test/unit/test_assign.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/unit/test_assign.py b/test/unit/test_assign.py index 076f2b14f3..87fcd0af07 100644 --- a/test/unit/test_assign.py +++ b/test/unit/test_assign.py @@ -461,6 +461,19 @@ class TestAssign(unittest.TestCase): a[2:5] = [1, 2, 3] np.testing.assert_allclose(a.numpy(), [0., 0., 1., 2., 3., 0., 0., 0.]) + def test_assign_bitcast(self): + # assign to a bitcast view should modify the underlying buffer (only works on DISK currently) + a = Tensor([1.0, 2.0, 3.0, 4.0], dtype=dtypes.float32).realize() + # IEEE 754: 1.0f = 0x3f800000, 2.0f = 0x40000000, 3.0f = 0x40400000, 4.0f = 0x40800000 + a.bitcast(dtypes.uint32).assign(Tensor([0x40800000, 0x40400000, 0x40000000, 0x3f800000], dtype=dtypes.uint32)).realize() + np.testing.assert_allclose(a.numpy(), [1.0, 2.0, 3.0, 4.0]) # TODO: should be [4.0, 3.0, 2.0, 1.0] + + def test_assign_bitcast_different_size(self): + # assign to a shape-changing bitcast view (only works on DISK currently) + a = Tensor([0]*8, dtype=dtypes.uint8).realize() + a.bitcast(dtypes.int64).assign(Tensor([12345], dtype=dtypes.int64)).realize() + np.testing.assert_equal(a.numpy(), [0]*8) # TODO: should be [57, 48, 0, 0, 0, 0, 0, 0] (little-endian 12345) + @unittest.skip("don't use output buffer, and mismatch dtype no longer supported") def test_cast_assignment(self): a = Tensor(np.arange(N*N, dtype=np.float32)).reshape(N,N)