mlx.core.allclose#

allclose(a: array, b: array, /, rtol: float = 1e-05, atol: float = 1e-08, *, equal_nan: bool = False, stream: None | Stream | Device = None) array#

Approximate comparison of two arrays.

Infinite values are considered equal if they have the same sign, NaN values are not equal unless equal_nan is True.

The arrays are considered equal if:

all(abs(a - b) <= (atol + rtol * abs(b)))

Note unlike array_equal(), this function supports numpy-style broadcasting.

Parameters:
  • a (array) – Input array.

  • b (array) – Input array.

  • rtol (float) – Relative tolerance.

  • atol (float) – Absolute tolerance.

  • equal_nan (bool) – If True, NaNs are considered equal. Defaults to False.

Returns:

The boolean output scalar indicating if the arrays are close.

Return type:

array