aesara.tensor.isclose#
- aesara.tensor.isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source]#
Implements Numpy’s
isclose
on tensors.The tolerance values are positive, typically very small numbers. The relative difference (
rtol
* abs(b
)) and the absolute differenceatol
are added together to compare against the absolute difference betweena
andb
.absolute(a - b) <= (atol + rtol * absolute(b))
- Parameters:
a (tensor) – Input to compare.
b (tensor) – Input to compare.
rtol (float) – The relative tolerance parameter.
atol (float) – The absolute tolerance parameter.
equal_nan (bool) – Whether to consider nan’s in the same place to be close
- Returns:
A boolean (int8) array where two arrays are element-wise equal within a tolerance.
- Return type:
int8
Notes
Not a symmetric equation. See Numpy’s documentation.
Examples
>>> import aesara >>> import numpy as np >>> a = _asarray([1e10, 1e-7], dtype="float64") >>> b = _asarray([1.00001e10, 1e-8], dtype="float64") >>> aesara.tensor.isclose(a, b).eval() array([1, 0], dtype=int8) >>> a = _asarray([1e10, 1e-8], dtype="float64") >>> b = _asarray([1.00001e10, 1e-9], dtype="float64") >>> aesara.tensor.isclose(a, b).eval() array([1, 1], dtype=int8) >>> a = _asarray([1e10, 1e-8], dtype="float64") >>> b = _asarray([1.0001e10, 1e-9], dtype="float64") >>> aesara.tensor.isclose(a, b).eval() array([0, 1], dtype=int8) >>> a = _asarray([1.0, np.nan], dtype="float64") >>> b = _asarray([1.0, np.nan], dtype="float64") >>> aesara.tensor.isclose(a, b).eval() array([1, 0], dtype==int8) >>> a = _asarray([1.0, np.nan], dtype="float64") >>> b = _asarray([1.0, np.nan], dtype="float64") >>> aesara.tensor.isclose(a, b, equal_nan=True).eval() array([1, 1], dtype==int8) >>> a = _asarray([1.0, np.inf], dtype="float64") >>> b = _asarray([1.0, -np.inf], dtype="float64") >>> aesara.tensor.isclose(a, b).eval() array([1, 0], dtype==int8) >>> a = _asarray([1.0, np.inf], dtype="float64") >>> b = _asarray([1.0, np.inf], dtype="float64") >>> aesara.tensor.isclose(a, b).eval() array([1, 1], dtype==int8)