testing no inplace change to the hashed item
(self)
| 73 | @unittest.skipUnless(has_cp and has_kvikio_numpy, "Requires CuPy and kvikio library.") |
| 74 | class TestDataset(unittest.TestCase): |
| 75 | def test_cache(self): |
| 76 | """testing no inplace change to the hashed item""" |
| 77 | for p in TEST_NDARRAYS[:2]: |
| 78 | shape = (1, 10, 9, 8) |
| 79 | items = [p(np.arange(0, np.prod(shape)).reshape(shape))] |
| 80 | |
| 81 | with tempfile.TemporaryDirectory() as tempdir: |
| 82 | ds = GDSDataset( |
| 83 | data=items, |
| 84 | transform=_InplaceXform(), |
| 85 | cache_dir=tempdir, |
| 86 | device=0, |
| 87 | pickle_module="pickle", |
| 88 | # TODO: was pickle.HIGHEST_PROTOCOL but this wasn't compatible with torch.load, need to improve compatibility |
| 89 | pickle_protocol=torch.serialization.DEFAULT_PROTOCOL, |
| 90 | ) |
| 91 | assert_allclose(items[0], p(np.arange(0, np.prod(shape)).reshape(shape))) |
| 92 | ds1 = GDSDataset(items, transform=_InplaceXform(), cache_dir=tempdir, device=0) |
| 93 | assert_allclose(ds[0], ds1[0], type_test=False) |
| 94 | assert_allclose(items[0], p(np.arange(0, np.prod(shape)).reshape(shape))) |
| 95 | |
| 96 | ds = GDSDataset( |
| 97 | items, transform=_InplaceXform(), cache_dir=tempdir, hash_transform=json_hashing, device=0 |
| 98 | ) |
| 99 | assert_allclose(items[0], p(np.arange(0, np.prod(shape)).reshape(shape))) |
| 100 | ds1 = GDSDataset( |
| 101 | items, transform=_InplaceXform(), cache_dir=tempdir, hash_transform=json_hashing, device=0 |
| 102 | ) |
| 103 | assert_allclose(ds[0], ds1[0], type_test=False) |
| 104 | assert_allclose(items[0], p(np.arange(0, np.prod(shape)).reshape(shape))) |
| 105 | |
| 106 | def test_metatensor(self): |
| 107 | shape = (1, 10, 9, 8) |
nothing calls this directly
no test coverage detected