Skip to main content

function

assert_almost_equal

assert_almost_equal[type: DType, size: Int](lhs: SIMD[type, size], rhs: SIMD[type, size], /, *, msg: String = "", atol: SIMD[type, 1] = #kgen.float_literal<1|100000000>, rtol: SIMD[type, 1] = #kgen.float_literal<1|100000>, equal_nan: Bool = 0)

Asserts that the input values are equal up to a tolerance. If it is not then an Error is raised.

When the type is boolean or integral, then equality is checked. When the type is floating-point, then this checks if the two input values are numerically the close using the abs(lhsrhs)<=max(rtolmax(abs(lhs),abs(rhs)),atol)abs(lhs - rhs) <= max(rtol * max(abs(lhs), abs(rhs)), atol) formula.

Constraints:

The type must be boolean, integral, or floating-point.

Parameters:

  • type (DType): The dtype of the left- and right-hand-side SIMD vectors.
  • size (Int): The width of the left- and right-hand-side SIMD vectors.

Args:

  • lhs (SIMD[type, size]): The lhs of the equality.
  • rhs (SIMD[type, size]): The rhs of the equality.
  • msg (String): The message to print.
  • atol (SIMD[type, 1]): The absolute tolerance.
  • rtol (SIMD[type, 1]): The relative tolerance.
  • equal_nan (Bool): Whether to treat nans as equal.

Raises:

An Error with the provided message if assert fails and None otherwise.