Operation on a tensor without using loop

Hi,

I have a tensor like this:

tensor([[[[ 1.,  2.,  3., 4., 5., 6., 7., 8.]]],
        [[[9., 10., 11., 12., 13., 14., 15., 16.]]]])

and I want to do a summation without any loop like this:

1+2 + 5+6
2+3 + 6+7
3+4 + 7+8

as the input tensor is in a batch mode, the operation should be done in batch mode.
I think it is possible by changes the shape of tensor, but I do not know how to organize it.
Do you have any idea about it?

Thanks
Best Regards

I think I could solve it. For who has the same problem, here is the code:

a = torch.tensor([[[[ 1.,  2.,  3., 4., 5., 6., 7., 8.]]],
        [[[9., 10., 11., 12., 13., 14., 15., 16.]]]])
print(a)
b = a.view(2,1,2,4)
print(b)
c = b.unfold(2, 2, 2).unfold(3, 2, 2).contiguous().view(2, 2, 2, 2)
print(c)
d= c.sum(2, keepdim=True).sum(3, keepdim=True)
print(d)

Regards