How do I check if two PyTorch tensors are semantically equal?
Given floating point errors, I want to know if the the elements differ only by a small epsilon value.
At the time of writing, this is a undocumented function in the latest stable release (0.4.1), but the documentation is in the master (unstable)
branch.
torch.allclose()
will return a boolean indicating whether all element-wise differences are equal allowing for a margin of error.
Additionally, there's the undocumented isclose()
:
>>> torch.isclose(torch.Tensor([1]), torch.Tensor([1.00000001]))
tensor([1], dtype=torch.uint8)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With