allclose
- paddle.compat. allclose ( input: Tensor, other: Tensor, rtol: float = 1e-05, atol: float = 1e-08, equal_nan: bool = False, name: str | None = None ) bool [source]
-
Check if all \(input\) and \(other\) satisfy the condition:
\[\left| input - other \right| \leq atol + rtol \times \left| other \right|\]elementwise, for all elements of \(input\) and \(other\). This is analogous to \(numpy.allclose\), namely that it returns \(True\) if two tensors are elementwise equal within a tolerance.
- Parameters
-
input (Tensor) – The input tensor, it’s data type should be float16, float32, float64.
other (Tensor) – The input tensor, it’s data type should be float16, float32, float64.
rtol (float, optional) – The relative tolerance. Default: \(1e-5\) .
atol (float, optional) – The absolute tolerance. Default: \(1e-8\) .
equal_nan (bool, optional) – ${equal_nan_comment}. Default: False.
name (str|None, optional) – Name for the operation. For more information, please refer to api_guide_Name. Default: None.
- Returns
-
True if the two tensors are elementwise equal within a tolerance, False otherwise.
- Return type
-
bool
Examples
>>> import paddle >>> x = paddle.to_tensor([10000.0, 1e-07]) >>> y = paddle.to_tensor([10000.1, 1e-08]) >>> result1 = paddle.compat.allclose(x, y, rtol=1e-05, atol=1e-08, equal_nan=False, name="ignore_nan") >>> print(result1) False >>> result2 = paddle.compat.allclose(x, y, rtol=1e-05, atol=1e-08, equal_nan=True, name="equal_nan") >>> print(result2) False
