cirq.Tolerance

class cirq.Tolerance(rtol: float = 1e-05, atol: float = 1e-08, equal_nan: bool = False)[source]

Specifies thresholds for doing approximate equality.

__init__(rtol: float = 1e-05, atol: float = 1e-08, equal_nan: bool = False) → None[source]

Initializes a Tolerance instance with the specified parameters.

Notes

Matrix Comparisons (methods beginning with “all_”) are done by
numpy.allclose, which considers x and y
to be close when abs(x - y) <= atol + rtol * abs(y). See
numpy.allclose’s documentation for more details. The scalar
methods perform the same calculations without the numpy
matrix construction.
Parameters:
  • rtol – Relative tolerance.
  • atol – Absolute tolerance.
  • equal_nan – Whether NaNs are equal to each other.

Methods

all_close(a, b)
all_near_zero(a)
all_near_zero_mod(a, period)
close(a, b)
near_zero(a)
near_zero_mod(a, period)

Attributes

DEFAULT
ZERO