I rewrite as follow, are they the right code format?
class subtract_neighbor_sample(nn.Module):
def init(self, device):
super(subtract_neighbor_sample, self).init()
self.device = device
def forward(self, x):
    output = torch.FloatTensor(x.shape[0], x.shape[1]).to(self.device)
    for i in range(x.shape[0]):
        if i % 2 == 0:
            output[i, :] = x[i, :] - x[i + 1, :]
            output[i + 1, :] = x[i + 1, :] - x[i, :]
    return output