(self)
| 34 | raise RuntimeError('make sure tmp_test_chunked_memmap is empty to run the test') |
| 35 | |
| 36 | def test_write(self): |
| 37 | |
| 38 | # create random array |
| 39 | samples_shape = [20, 10, 4] |
| 40 | working_dir = 'tmp_test_chunked_memmap' |
| 41 | samples = np.random.randn(*samples_shape).astype('float32') |
| 42 | |
| 43 | # determine chunk_idxs |
| 44 | total_chunks = 3 |
| 45 | chunk_idxs = np.random.randint(total_chunks, size=samples_shape[0]) |
| 46 | |
| 47 | # create chunked_memmap |
| 48 | chunked_memmap = ChunkedMemmap(working_dir, remove_exist=True) |
| 49 | chunked_memmap.add_all_samples(samples, chunk_idxs, dtype='float32') |
| 50 | |
| 51 | # check if the same |
| 52 | arr = np.zeros(samples_shape) |
| 53 | for i in range(samples_shape[0]): |
| 54 | arr[i] = chunked_memmap[i] |
| 55 | |
| 56 | assert np.allclose(samples, arr) |
| 57 | |
| 58 | |
| 59 | def test_multithread_write(self): |
nothing calls this directly
no test coverage detected