def test_get_shifted_base(): data = np.random.random((6, 7)) tile_origin = np.array((0, 0)) tile_shape = np.array((6, 7)) target_tup, offsets = get_shifted( arr_shape=np.array(data.shape), tile_origin=tile_origin, tile_shape=tile_shape, shift=np.array((0, 0)) ) print(target_tup) print(offsets) (target_slice, source_slice) = to_slices(target_tup, offsets) print(target_slice, source_slice) res = np.full(tile_shape, 17, dtype=data.dtype) res[target_slice] = data[source_slice] print("result:", res) print("data:", data) assert np.all(res == data) assert res.dtype == data.dtype assert res.shape == data.shape
def test_get_shifted_minus_partial(): data_shape = np.array((6, 7)) data = np.random.random(data_shape) tile_origin = np.array((1, 2)) tile_shape = np.array((3, 4)) target_tup, offsets = get_shifted( arr_shape=np.array(data.shape), tile_origin=tile_origin, tile_shape=tile_shape, shift=np.array((-1, -2)) ) print(target_tup) print(offsets) (target_slice, source_slice) = to_slices(target_tup, offsets) res = np.full(tile_shape, 17, dtype=data.dtype) res[target_slice] = data[source_slice] print("result:", res) print("data:", data) assert np.all(res == data[:3, :4]) assert res.dtype == data.dtype
def test_get_shifted_plus(): data_shape = np.array((4, 5)) data = np.random.random(data_shape) tile_origin = np.array((0, 0)) tile_shape = data_shape target_tup, offsets = get_shifted( arr_shape=np.array(data.shape), tile_origin=tile_origin, tile_shape=tile_shape, shift=np.array((1, 2)) ) print(target_tup) print(offsets) (target_slice, source_slice) = to_slices(target_tup, offsets) res = np.full(tile_shape, 17, dtype=data.dtype) res[target_slice] = data[source_slice] print("result:", res) print("data:", data) assert np.all(res[:-1, :-2] == data[1:, 2:]) assert np.all(res[-1:] == 17) assert np.all(res[:, -2:] == 17) assert res.dtype == data.dtype assert res.shape == data.shape