jax.numpy.isclose
Contents
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.infinawill be considered equal tojnp.infinb.- Parameters:
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 inawill be consideredequal to NaNs inb. Default isFalse.
- Returns:
A new array containing boolean values indicating whether the input arraysare element-wise approximately equal within the specified tolerances.
- Return type:
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)
Contents
