Check if the elements of two arrays are approximately equal within a tolerance.
JAX implementation of numpy.allclose()
.
Essentially this function evaluates the following condition:
\[|a - b| \le \mathtt{atol} + \mathtt{rtol} * |b|\]
jnp.inf
in a
will be considered equal to jnp.inf
in b
.
a (ArrayLike) – first input array to compare.
b (ArrayLike) – second input array to compare.
rtol (ArrayLike) – relative tolerance used for approximate equality. Default = 1e-05.
atol (ArrayLike) – absolute tolerance used for approximate equality. Default = 1e-08.
equal_nan (bool) – Boolean. If True
, NaNs in a
will be considered equal to NaNs in b
. Default is False
.
A new array containing boolean values indicating whether the input arrays are element-wise approximately equal within the specified tolerances.
Examples
>>> jnp.isclose(jnp.array([1e6, 2e6, jnp.inf]), jnp.array([1e6, 2e7, jnp.inf])) Array([ True, False, True], dtype=bool) >>> jnp.isclose(jnp.array([1e6, 2e6, 3e6]), ... jnp.array([1.00008e6, 2.00008e7, 3.00008e8]), rtol=1e3) Array([ True, True, True], dtype=bool) >>> jnp.isclose(jnp.array([1e6, 2e6, 3e6]), ... jnp.array([1.00001e6, 2.00002e6, 3.00009e6]), atol=1e3) Array([ True, True, True], dtype=bool) >>> jnp.isclose(jnp.array([jnp.nan, 1, 2]), ... jnp.array([jnp.nan, 1, 2]), equal_nan=True) Array([ True, True, True], dtype=bool)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4