def test_threaded_read(self, file_, threads): shape = (20, 20) chunks = (10, 10) data = np.arange(np.product(shape), dtype=int).reshape(shape) ds = self.dataset(file_, data, chunks=chunks) ds.threads = threads read_start = (5, 5) read_shape = (10, 10) slicing = to_slice(read_start, read_shape) assert np.array_equal(ds[slicing], data[slicing])
def test_thread_read_fn(start, shape): random = np.random.RandomState(1991) data = random.random_sample((30, 30)) chunks = (10, 10) def fn(start_coord, block_shape): stop_coord = np.array(start_coord) + block_shape slicing = tuple( slice(sta, sto) for sta, sto in zip(start_coord, stop_coord)) return data[slicing] out = thread_read_fn(start, shape, chunks, data.shape, fn, threads=1) slicing = to_slice(start, shape) expected = data[slicing] assert np.allclose(expected, out)
def test_thread_write_fn(start, shape): random = np.random.RandomState(1991) data = random.random_sample((30, 30)) chunks = (10, 10) def fn(start_coord, arr): slicing = to_slice(start_coord, arr.shape) data[slicing] = arr expected = data.copy() to_write = np.ones(shape, dtype=data.dtype) thread_write_fn(start, to_write, chunks, data.shape, fn, threads=1) slicing = to_slice(start, shape) expected[slicing] = to_write assert np.allclose(expected, data)
def test_threaded_write(self, file_, threads): shape = (20, 20) chunks = (10, 10) data = np.ones(shape, dtype=int) ds = self.dataset(file_, data, chunks=chunks) ds.threads = threads write_start = (5, 5) write_shape = (10, 10) write_slice = to_slice(write_start, write_shape) data[write_slice] = 9 ds[write_slice] = 9 assert np.array_equal(data, ds[:])
def fn(start_coord, arr): slicing = to_slice(start_coord, arr.shape) data[slicing] = arr
def test_to_slice(start, shape, expected): assert to_slice(start, shape) == expected
def inner_fn(offset, shape): slices = to_slice(offset, shape) return self._impl[slices]
def inner_fn(offset, array): slices = to_slice(offset, array.shape) self._impl[slices] = array