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
8 changes: 5 additions & 3 deletions pytensor/graph/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,11 @@ def __hash__(self):
if "__eq__" not in dct:

def __eq__(self, other):
return type(self) is type(other) and tuple(
getattr(self, a) for a in props
) == tuple(getattr(other, a) for a in props)
return self is other or (
type(self) is type(other)
and tuple(getattr(self, a) for a in props)
== tuple(getattr(other, a) for a in props)
)

dct["__eq__"] = __eq__

Expand Down
13 changes: 13 additions & 0 deletions pytensor/tensor/elemwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,19 @@ def __init__(
self.__setstate__(self.__dict__)
super().__init__(openmp=openmp)

def __eq__(self, other):
# Hot in rewriting. Identity accepts the singleton-op common case, and
# the scalar_op type check rejects mismatches without paying for the
# props tuples the generated __eq__ would build.
if self is other:
return True
return (
type(self) is type(other)
and type(self.scalar_op) is type(other.scalar_op)
and self.scalar_op == other.scalar_op
and self.inplace_pattern == other.inplace_pattern
)

def __getstate__(self):
d = copy(self.__dict__)
d.pop("ufunc")
Expand Down
Loading
Loading