Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] Fixed crash caused by reversing bitwise operations #4852

Merged
merged 1 commit into from
Feb 10, 2020
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
9 changes: 9 additions & 0 deletions python/tvm/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,21 @@ def __rshift__(self, other):
def __and__(self, other):
return _make.bitwise_and(self, other)

def __rand__(self, other):
return _make.bitwise_and(other, self)

def __or__(self, other):
return _make.bitwise_or(self, other)

def __ror__(self, other):
return _make.bitwise_or(other, self)

def __xor__(self, other):
return _make.bitwise_xor(self, other)

def __rxor__(self, other):
return _make.bitwise_xor(other, self)

def __invert__(self):
return _make.Call(self.dtype, "bitwise_not", [self], Call.PureIntrinsic, None, 0)

Expand Down
3 changes: 3 additions & 0 deletions tests/python/unittest/test_lang_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ def test_bitwise():
assert str(x & y) == 'bitwise_and(x, y)'
assert str(x | y) == 'bitwise_or(x, y)'
assert str(x ^ y) == 'bitwise_xor(x, y)'
assert str(10 & x) == 'bitwise_and(10, x)'
assert str(10 | x) == 'bitwise_or(10, x)'
assert str(10 ^ x) == 'bitwise_xor(10, x)'
assert str(~x) == 'bitwise_not(x)'
assert(tvm.const(1, "int8x2") >> 1).dtype == "int8x2"
assert(x >> tvm.const(1, "int32x2")).dtype == "int32x2"
Expand Down