Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pytato/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,13 @@ def __len__(self) -> int:
def __iter__(self) -> Iterator[str]:
return iter(self._data)

def __eq__(self, other: Any) -> bool:
if self is other:
return True

return (isinstance(other, DictOfNamedArrays)
and self._data == other._data)

# }}}


Expand Down
12 changes: 12 additions & 0 deletions test/test_pytato.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,18 @@ class BestArrayTag(Tag):
assert any(isinstance(tag, BestArrayTag) for tag in y.tags)


def test_dict_of_named_arrays_comparison():
# See https://github.com/inducer/pytato/pull/137
x = pt.make_placeholder("x", (10, 4), float)
dict1 = pt.make_dict_of_named_arrays({"out": 2 * x})
dict2 = pt.make_dict_of_named_arrays({"out": 2 * x})
dict3 = pt.make_dict_of_named_arrays({"not_out": 2 * x})
dict4 = pt.make_dict_of_named_arrays({"out": 3 * x})
assert dict1 == dict2
assert dict1 != dict3
assert dict1 != dict4


if __name__ == "__main__":
if len(sys.argv) > 1:
exec(sys.argv[1])
Expand Down