jax.numpy.isclose — JAX documentation (original) (raw)

jax.numpy.isclose#

jax.numpy.isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source]#

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.

Parameters:

Returns:

A new array containing boolean values indicating whether the input arrays are element-wise approximately equal within the specified tolerances.

Return type:

Array

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)