Reputation: 1623
What is the easiest way to check that a torch tensor’s dtype is an integer type?
I ultimately don’t care if it is torch.uint8
or torch.int32
for example, I just want to know if it contains integers.
I also don’t care on which device it is located
I could write something like
tensor.dtype in (torch.int8, torch.uint8, torch.int16,...)
But I was wondering if there was a more elegant way
Upvotes: 1
Views: 931
Reputation: 474
Are torch.is_floating_point(...)
and torch.is_complex(...)
enough?
# True
torch.is_floating_point(torch.tensor([1.2]))
# False
torch.is_floating_point(torch.tensor([1]))
Upvotes: 1