Added correct isinf handling for Integral tensors (#15489)

Summary:
Currently torch.isinf on integral tensor will raise RuntimeError: value cannot be converted to type int16_t without overflow: inf.
This pr will suppress the error and return false(0) for all integral tensors. The behavior will also be consistent with np.isinf
Pull Request resolved: https://github.com/pytorch/pytorch/pull/15489

Reviewed By: zou3519

Differential Revision: D13540786

Pulled By: flashhack

fbshipit-source-id: e730dea849da6a59f3752d347bcfbadfd12c6483
This commit is contained in:
Frank Zhang
2018-12-26 06:32:44 -08:00
committed by Facebook Github Bot
parent d602ddcda3
commit d4712ee218
3 changed files with 21 additions and 2 deletions

View File

@ -240,6 +240,8 @@ def isinf(tensor):
"""
if not isinstance(tensor, torch.Tensor):
raise ValueError("The argument is not a tensor", str(tensor))
if tensor.dtype in [torch.uint8, torch.int8, torch.int16, torch.int32, torch.int64]:
return torch.zeros_like(tensor, dtype=torch.uint8)
return tensor.abs() == inf