torch.isclose
- torch.isclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False) → Tensor
-
返回一个新张量,其中包含布尔值,表示
input
中的每个元素是否与other
中的对应元素“接近”。这里的接近性定义为:$\lvert \text{input} - \text{other} \rvert \leq \texttt{atol} + \texttt{rtol} \times \lvert \text{other} \rvert$其中
input
和other
是有限值。当它们是非有限值时,只有在相等的情况下才被认为是接近的。如果equal_nan
为 True,则 NaN 被视为彼此相等。- 参数
示例:
>>> torch.isclose(torch.tensor((1., 2, 3)), torch.tensor((1 + 1e-10, 3, 4))) tensor([ True, False, False]) >>> torch.isclose(torch.tensor((float('inf'), 4)), torch.tensor((float('inf'), 6)), rtol=.5) tensor([True, True])