Mojo function
assert_almost_equal
assert_almost_equal[type: DType, size: Int](lhs: SIMD[type, size], rhs: SIMD[type, size], msg: String = String(""), *, atol: SIMD[type, 1] = SIMD(#kgen.float_literal<1|100000000>), rtol: SIMD[type, 1] = SIMD(#kgen.float_literal<1|100000>), equal_nan: Bool = False, location: Optional[_SourceLocation] = Optional(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!