PyTorch torch.allclose Function
PyTorch torch Reference Manual
torch.allcloseA function in PyTorch used to check whether all elements of two tensors are close. It is used to determine whether two tensors are equal within a given tolerance.
Function Definition
torch.allclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False)
Usage Example
Example
import torch
# Create two similar tensors
x = torch.tensor([1.0, 2.0, 3.0])
y = torch.tensor([1.0, 2.0, 3.0 + 1e-9])
# Check whether all elements are close
result = torch.allclose(x, y)
print(result)
# Create two similar tensors
x = torch.tensor([1.0, 2.0, 3.0])
y = torch.tensor([1.0, 2.0, 3.0 + 1e-9])
# Check whether all elements are close
result = torch.allclose(x, y)
print(result)
The output result is:
True
Other Extensions