Skip to content

Commit

Permalink
DimensionTag equality docs
Browse files Browse the repository at this point in the history
  • Loading branch information
albertz committed Nov 22, 2021
1 parent bff669c commit 6228964
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions returnn/tf/util/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,15 @@ def is_equal(self, other, ignore_feature_dim=False, allow_same_feature_dim=False
undefined_matches=False, derived_matches=False):
"""
Compares self to other for equality.
Note that the default behavior is very restrictive.
Use functions such as :func:`get_all_dimension_tags` or :func:`get_existing_tag_from_collection`
to explicitly specify the behavior for the comparison.
Also note that the definition is slightly ad-hoc for some cases,
and might potentially change in the future.
https://github.com/rwth-i6/returnn/issues/634
:param DimensionTag other:
:param bool ignore_feature_dim:
:param bool allow_same_feature_dim:
Expand Down Expand Up @@ -540,6 +545,7 @@ def __eq__(self, other):
"""
:param DimensionTag other:
:rtype: bool
:return: :func:`is_equal` with default options
"""
if not isinstance(other, DimensionTag):
return False
Expand All @@ -553,6 +559,10 @@ def __ne__(self, other):
return not (self == other)

def __hash__(self):
"""
:rtype: int
:return: hash, matching to :func:`__eq__`
"""
# This must match the behavior in __eq__, which is is_equal with default options.
# I.e. different hash implies not equal (but same hash not necessarily equal).
if self.is_batch_dim():
Expand Down

0 comments on commit 6228964

Please sign in to comment.