This is an automated email from the ASF dual-hosted git repository.

liuyizhi pushed a commit to branch v0.6
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git


The following commit(s) were added to refs/heads/v0.6 by this push:
     new 05f38c5  [BACKPORT-0.6] Fixed crash caused by reversing bitwise 
operations (#5866)
05f38c5 is described below

commit 05f38c5bd6efce86cad2bd540ac5288416a074c5
Author: Yizhi Liu <[email protected]>
AuthorDate: Sun Jun 21 13:25:58 2020 -0700

    [BACKPORT-0.6] Fixed crash caused by reversing bitwise operations (#5866)
    
    Co-authored-by: pankratz <[email protected]>
    
    Co-authored-by: pankratz <[email protected]>
---
 python/tvm/expr.py                       | 9 +++++++++
 tests/python/unittest/test_lang_basic.py | 3 +++
 2 files changed, 12 insertions(+)

diff --git a/python/tvm/expr.py b/python/tvm/expr.py
index 733f57a..2ba0c06 100644
--- a/python/tvm/expr.py
+++ b/python/tvm/expr.py
@@ -113,12 +113,21 @@ class ExprOp(object):
     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)
 
diff --git a/tests/python/unittest/test_lang_basic.py 
b/tests/python/unittest/test_lang_basic.py
index 8b54ef9..0015d6d 100644
--- a/tests/python/unittest/test_lang_basic.py
+++ b/tests/python/unittest/test_lang_basic.py
@@ -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"

Reply via email to