Mojo 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, location: Optional[_SourceLocation] = #kgen.none)
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 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. - βlocation (
Optional[_SourceLocation]
): The location of the error (default to the__call_location
).
Raises:
An Error with the provided message if assert fails and None
otherwise.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!
π What went wrong?