All problems
Shifted Window Offset
Problem
Apply a cyclic shift to an image (used by shifted-window attention).
Move content down by dy and right by dx with wraparound, so out[i][j] = image[(i - dy) mod h][(j - dx) mod w].
Test cases
case 1
in: [[[1,2],[3,4]],1,0]
expected: [[3,4],[1,2]]
case 2
in: [[[1,2],[3,4]],0,1]
expected: [[2,1],[4,3]]
case 3
in: [[[1,2,3]],0,1]
expected: [[3,1,2]]
case 4
in: [[[1,2,3],[4,5,6],[7,8,9]],2,2]
expected: [[5,6,4],[8,9,7],[2,3,1]]
Starter codePython
def cyclic_shift(image, dy, dx):
# Your code here
pass4 test cases · run your code against them in the editor