From ea1f1d2b9dae70c0fc807b782f9431b85fed9bcc Mon Sep 17 00:00:00 2001 From: chenyu Date: Sun, 1 Feb 2026 16:46:04 -0500 Subject: [PATCH] test_assign_to_bitcast_view (#14483) currently disk allows assign same size dtype into a bitcasted view --- test/unit/test_disk_tensor.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/unit/test_disk_tensor.py b/test/unit/test_disk_tensor.py index 6d215b627a..fbc5b0f914 100644 --- a/test/unit/test_disk_tensor.py +++ b/test/unit/test_disk_tensor.py @@ -359,6 +359,15 @@ class TestDiskTensor(unittest.TestCase): with self.assertRaises(RuntimeError): t[0:4].bitcast(dtypes.int32).assign(Tensor([12345], dtype=dtypes.int64)) + def test_assign_to_bitcast_view(self): + # assign float values to a float32 view of a uint8 disk buffer (used by safe_save) + pathlib.Path(temp(fn:="dt_bitcast_view_assign")).unlink(missing_ok=True) + t = Tensor.empty(32, device=f"disk:{temp(fn)}", dtype=dtypes.uint8) + # create float32 view of bytes 8-24 (4 floats) + float_view = t[8:24].bitcast(dtypes.float32) + float_view.assign(Tensor([1.0, 2.0, 3.0, 4.0], dtype=dtypes.float32, device="CPU")) + np.testing.assert_array_equal(float_view.numpy(), [1.0, 2.0, 3.0, 4.0]) + def test_assign_cross_device(self): # disk assign allows cross-device (source on GPU/CPU, target on disk) pathlib.Path(temp(fn:="dt_assign_cross")).unlink(missing_ok=True)