MCPcopy Create free account
hub / github.com/apple/ml-pointersect / test_write

Method test_write

tests/cdslib/data/test_chunked_memmap.py:36–56  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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):

Callers

nothing calls this directly

Calls 2

add_all_samplesMethod · 0.95
ChunkedMemmapClass · 0.90

Tested by

no test coverage detected