Approximately compares two objects.
cirq.approx_eq(
val: Any, other: Any, *, atol: Union[int, float] = 1e-08
) -> bool
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.
Args |
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.
|
Raises |
AttributeError
|
If there is insufficient information to determine whether
the objects are approximately equal.
|