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