Sorry, here is a description of the terms used
image583×658 55.1 KB
But you are right, and that is exactly what I am trying to do. And thank you, doing it your way for each of the 8 neighbours

y[:, :, 1:, 1:] - y[:, :, :-1, :-1]).abs().sum()

Looks cleaner and more efficient than my initial plan to use torch.roll for each neighbour.