Exemplo n.º 1
0
    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])
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
    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[:])
Exemplo n.º 5
0
 def fn(start_coord, arr):
     slicing = to_slice(start_coord, arr.shape)
     data[slicing] = arr
Exemplo n.º 6
0
def test_to_slice(start, shape, expected):
    assert to_slice(start, shape) == expected
Exemplo n.º 7
0
 def inner_fn(offset, shape):
     slices = to_slice(offset, shape)
     return self._impl[slices]
Exemplo n.º 8
0
 def inner_fn(offset, array):
     slices = to_slice(offset, array.shape)
     self._impl[slices] = array