Sample integers greater than 1e19 (`torch.long` overflow)

I need to sample N random integers between 0 and N_max, with N_max > 10^19. If I try,

N_max = int(1e20)

I get overflow:

RuntimeError: Overflow when unpacking long

Is there a way to do it?

1 Like

I receive the same error with code below

N_max = int(1e20)
torch.tensor([N_max], dtype=torch.long)

So, I think it comes down to torch.long type not being able to handle integers that cannot fit into 64 whereas python int automatically adapts bit size whenever u64 bit range is exceeded.
After my research, I was not able to see anything about torch.long (or any other type in torch) dedicated to handling integers that cannot fit into u64 range.