I am trying to implement a function similar to numpy.roll function. To use cuda, I want to use only torch Tensors, but it seems to be hard.
Ultimately, I want to implement image gradient with forward difference and Neumann boundary condition. For example, the numpy version of it is as follows:
def grad(u):
    # u: 2-d images
    ux = np.roll(u, -1, axis=1) - u
    uy = np.roll(u, -1, axis=0) - u
    ux[:,-1] = 0
    uy[-1,:] = 0

I tried to use [-1, 1] filter, using torch.nn.Functional.conv2d. Because there is no boundary option except zero padding and the filter is even filter, it looks complicated.
Is there someone who can help implement one like np.roll?