isclose | Modular

Mojo function

isclose[dtype: DType, width: Int, *, symmetrical: Bool = True](a: SIMD[dtype, width], b: SIMD[dtype, width], *, atol: Float64 = 1.0E-8, rtol: Float64 = 1.0000000000000001E-5, equal_nan: Bool = False) -> SIMD[DType.bool, width]

Returns a boolean SIMD vector indicating which element pairs of a and b are equal within a given tolerance.

For floating-point dtypes, the following criteria apply:

  • Symmetric (Python math.isclose style), when symmetrical is true:
    |a - b| ≤ max(atol, rtol * max(|a|, |b|))
  • Asymmetric (NumPy style), when symmetrical is false:
    |a - b| ≤ atol + rtol * |b|

NaN values are considered equal only if equal_nan is true.

Parameters:

  • dtype (DType): Element type of the input and output vectors.
  • width (Int): Number of lanes in each SIMD vector.
  • symmetrical (Bool): If true, use the symmetric comparison formula (default: true).

Args:

  • a (SIMD): First input vector.
  • b (SIMD): Second input vector.
  • atol (Float64): Absolute tolerance.
  • rtol (Float64): Relative tolerance.
  • equal_nan (Bool): If true, treat NaNs as equal (default: false).

Returns:

SIMD: A boolean vector where a and b are equal within the given tolerance.