cirq.approx_eq

cirq.approx_eq(val: Any, other: Any, *, atol: Union[int, float] = 1e-08) → bool[source]

Approximately compares two objects.

If val implements SupportsApproxEquality protocol then it is invoked and
takes precedence over all other checks:
  • For primitive numeric types int and float approximate equality is delegated to math.isclose().
  • For complex primitive type the real and imaginary parts are treated independently and compared using math.isclose().
  • For val and other both iterable of the same length, consecutive elements are compared recursively. Types of val and other does not necessarily needs to match each other. They just need to be iterable and have the same structure.
Parameters:
  • val – Source object for approximate comparison.
  • other – Target object for approximate comparison.
  • atol – The minimum absolute tolerance. See np.isclose() documentation for details. Defaults to 1e-8 which matches np.isclose() default absolute tolerance.
Returns:

True if objects are approximately equal, False otherwise.