@richard So would this:
self.x_diff = input[:, 1:-2, 1:-2] + input[:, 1:-2, 2:-1] 
self.y_diff = input[:, 1:-2, 1:-2] + input[:, 2:-1, 1:-2]

be the same as this in Lua/Torch:
  self.x_diff:copy(input[{{}, {1, -2}, {1, -2}}])
  self.x_diff:add(-1, input[{{}, {1, -2}, {2, -1}}])
  self.y_diff:copy(input[{{}, {1, -2}, {1, -2}}])
  self.y_diff:add(-1, input[{{}, {2, -1}, {1, -2}}])

Or am I doing it wrong?