mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 13:44:15 +08:00
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:
committed by
Facebook Github Bot
parent
d602ddcda3
commit
d4712ee218
@ -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
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user