Skip to content

Commit

Permalink
[PYTHON] Improve equality wrapper (#567)
Browse files Browse the repository at this point in the history
use `object.__eq__`(default object identity comparison) as default
implementation of same_as. This should be OK since `EqualOp` and
`NotEqualOp` are pure Python object, `object.__eq__` is sufficient.
  • Loading branch information
wweic authored and tqchen committed Oct 19, 2017
1 parent 9a2f01a commit ab858e3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions python/tvm/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ class EqualOp(NodeGeneric, ExprOp):
b : Expr
Right operand.
"""
# This class is not manipulated by C++. So use python's identity check function is sufficient
same_as = object.__eq__

def __init__(self, a, b):
self.a = a
self.b = b
Expand Down Expand Up @@ -181,6 +184,9 @@ class NotEqualOp(NodeGeneric, ExprOp):
b : Expr
Right operand.
"""
# This class is not manipulated by C++. So use python's identity check function is sufficient
same_as = object.__eq__

def __init__(self, a, b):
self.a = a
self.b = b
Expand Down
9 changes: 9 additions & 0 deletions tests/python/unittest/test_lang_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ def test_bitwise():
assert str(~x) == 'bitwise_not(x)'


def test_equality():
a = tvm.var('a')
b = tvm.var('b')
c = (a == b)
assert not c
d = (c != c)
assert not d

if __name__ == "__main__":
test_cast()
test_attr()
Expand All @@ -148,3 +156,4 @@ def test_bitwise():
test_any()
test_all()
test_bitwise()
test_equality()

0 comments on commit ab858e3

Please sign in to comment.