Dear experts,
I am seeing that uint64 datatype in torch does not have a wraparound behavior on overflow/underflow (which is the expected behavior in C/C++ from my understanding). Below is my code:
import torch
A = torch.tensor([2 ** 40], dtype=torch.uint64)
B = torch.tensor([2 ** 40], dtype=torch.uint64)
C = A * B
print(C)
A = torch.tensor([2 ** 40], dtype=torch.long)
B = torch.tensor([2 ** 40], dtype=torch.long)
C = A * B
print(C)
Both prints out 0. For torch.long, I see this makes sense as overflow/underflow is usually undefined behaviour. But I am surprised to see this happening for uint64.
Below are some of the questions:
- Is this expected (is the unsigned number overflow behavior deviating from C/C++ for torch)?
- Is there a way for me to make it wraparound (e.g., by compiling the torch with a certain flag?)
- If not, is there any way I can achieve my desired behavior?
I appreciate any pointers in advance.