Skip to content

Commit

Permalink
change __eq__ method
Browse files Browse the repository at this point in the history
  • Loading branch information
aerubanov committed Jan 24, 2022
1 parent ba4631a commit d482291
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
19 changes: 6 additions & 13 deletions aesara/graph/fg.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,19 +465,12 @@ def change_node_input(
self.outputs[i] = new_var
else:
r = node.inputs[i]
if check:
if isinstance(r.type, aesara.sparse.SparseType):
fail = not (
isinstance(new_var.type, type(r.type))
and r.type.dtype == r.type.dtype
)
else:
fail = not r.type.is_super(new_var.type)
if fail:
raise TypeError(
f"The type of the replacement ({new_var.type}) must be "
f"compatible with the type of the original Variable ({r.type})."
)
if check and not r.type.is_super(new_var.type):
raise TypeError(
f"The type of the replacement ({new_var.type}) must be "
f"compatible with the type of the original Variable ({r.type})."
)

node.inputs[i] = new_var

if r is new_var:
Expand Down
35 changes: 22 additions & 13 deletions aesara/sparse/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ def may_share_memory(a, b):
def make_variable(self, name=None):
return self.Variable(self, name=name)

def __eq__(self, other):
return (
super().__eq__(other)
and type(self) == type(other)
and other.format == self.format
)
# def __eq__(self, other):
# return (
# super().__eq__(other)
# and type(self) == type(other)
# and other.format == self.format
# )

def __hash__(self):
return super().__hash__() ^ hash(self.format)
Expand Down Expand Up @@ -215,15 +215,24 @@ def value_zeros(self, shape):

return matrix_constructor(shape, dtype=self.dtype)

def __eq__(self, other):
if type(self) != type(other):
return NotImplemented

return other.dtype == self.dtype and other.format == self.format

def is_super(self, otype):
if (
isinstance(otype, type(self))
and otype.dtype == self.dtype
and otype.ndim == self.ndim
and self.format == otype.format
):
# if (
# isinstance(otype, SparseType)
# and otype.dtype == self.dtype
# and otype.ndim == self.ndim
# and self.format == otype.format
# and otype.broadcastable == self.broadcastable
# ):
# return True
# return False
if self == otype:
return True

return False


Expand Down

0 comments on commit d482291

Please sign in to comment.