Skip to main content
Log in

Mojo function

isclose

isclose[dtype: DType, width: Int, *, symmetrical: Bool = True](a: SIMD[dtype, width], b: SIMD[dtype, width], *, atol: SIMD[float64, 1] = __init__[__mlir_type.!pop.float_literal](1.0E-8), rtol: SIMD[float64, 1] = __init__[__mlir_type.!pop.float_literal](1.0000000000000001E-5), equal_nan: Bool = False) -> SIMD[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|))
    |a - b| ≤ max(atol, rtol * max(|a|, |b|))
  • Asymmetric (NumPy style), when symmetrical is false:
    |a - b| ≤ atol + rtol * |b|
    |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[dtype, width]): First input vector.
  • b (SIMD[dtype, width]): Second input vector.
  • atol (SIMD[float64, 1]): Absolute tolerance.
  • rtol (SIMD[float64, 1]): Relative tolerance.
  • equal_nan (Bool): If true, treat NaNs as equal (default: false).

Returns:

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

Was this page helpful?