allclose

Contents

allclose#

class brainunit.math.allclose(x, y, rtol=None, atol=None, equal_nan=False, **kwargs)#

Returns True if two arrays are element-wise equal within a tolerance.

The tolerance values are positive, typically very small numbers. The relative difference (rtol * abs(b)) and the absolute difference atol are added together to compare against the absolute difference between a and b.

NaNs are treated as equal if they are in the same place and if equal_nan=True. Infs are treated as equal if they are in the same place and of the same sign in both arrays.

Parameters:
  • x (saiunit.Quantity | Array | ndarray | bool | number | bool | int | float | complex) – Input arrays to compare.

  • y (saiunit.Quantity | Array | ndarray | bool | number | bool | int | float | complex) – Input arrays to compare.

  • rtol (float | saiunit.Quantity) – The relative tolerance parameter (see Notes).

  • atol (float | saiunit.Quantity) – The absolute tolerance parameter (see Notes).

  • equal_nan (bool) – Whether to compare NaN’s as equal. If True, NaN’s in a will be considered equal to NaN’s in b in the output array.

Returns:

allclose – True if the two arrays are element-wise equal within tolerance.

Return type:

bool | Array

Examples

>>> import saiunit as u
>>> import jax.numpy as jnp
>>> u.math.allclose(jnp.array([1.0, 2.0]),
...                  jnp.array([1.0, 2.0]))
Array(True, dtype=bool)