View source on GitHub |
Implements eq/ne/hash via a _value_equalityvalues method.
cirq.value_equality(
cls: Optional[type] = None,
*,
unhashable: bool = False,
distinct_child_types: bool = False,
manual_cls: bool = False,
approximate: bool = False
) -> Union[Callable[[type], type], type]
_value_equalityvalues is a method that the decorated class must implement.
_value_equality_approximatevalues is a method that the decorated class
might implement if special support for approximate equality is required.
This is only used when approximate argument is set. When approximate
argument is set and _value_equality_approximatevalues is not defined,
_value_equalityvalues values are used for approximate equality.
For example, this can be used to compare periodic values like angles: the
angle value can be wrapped with PeriodicValue
. When returned as part of
approximate values a special normalization will be done automatically to
guarantee correctness.
Note that the type of the decorated value is included as part of the value
equality values. This is so that completely separate classes with identical
equality values (e.g. a Point2D and a Vector2D) don't compare as equal.
Further note that this means that child types of the decorated type will be
considered equal to each other, though this behavior can be changed via
the 'distinct_child_typesargument. The type logic is implemented behind
the scenes by a
_value_equality_valuescls` method added to the class.