Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tic
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyuanbo
tic
Commits
4fdef3ad
Commit
4fdef3ad
authored
Oct 01, 2017
by
ziheng
Committed by
Tianqi Chen
Oct 01, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[LANG] Support for Bitwise Operation (#502)
* [LANG] Support for Bitwise Operation * Add test
parent
9c2fc095
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
0 deletions
+29
-0
python/tvm/expr.py
+18
-0
tests/python/unittest/test_lang_basic.py
+11
-0
No files found.
python/tvm/expr.py
View file @
4fdef3ad
...
...
@@ -62,6 +62,24 @@ class ExprOp(object):
def
__neg__
(
self
):
return
self
.
__mul__
(
-
1
)
def
__lshift__
(
self
,
other
):
return
_make
.
Call
(
self
.
dtype
,
"shift_left"
,
[
self
,
other
],
Call
.
PureIntrinsic
,
None
,
0
)
def
__rshift__
(
self
,
other
):
return
_make
.
Call
(
self
.
dtype
,
"shift_right"
,
[
self
,
other
],
Call
.
PureIntrinsic
,
None
,
0
)
def
__and__
(
self
,
other
):
return
_make
.
Call
(
self
.
dtype
,
"bitwise_and"
,
[
self
,
other
],
Call
.
PureIntrinsic
,
None
,
0
)
def
__or__
(
self
,
other
):
return
_make
.
Call
(
self
.
dtype
,
"bitwise_or"
,
[
self
,
other
],
Call
.
PureIntrinsic
,
None
,
0
)
def
__xor__
(
self
,
other
):
return
_make
.
Call
(
self
.
dtype
,
"bitwise_xor"
,
[
self
,
other
],
Call
.
PureIntrinsic
,
None
,
0
)
def
__invert__
(
self
):
return
_make
.
Call
(
self
.
dtype
,
"bitwise_not"
,
[
self
],
Call
.
PureIntrinsic
,
None
,
0
)
def
__lt__
(
self
,
other
):
return
_make
.
LT
(
self
,
other
)
...
...
tests/python/unittest/test_lang_basic.py
View file @
4fdef3ad
...
...
@@ -123,6 +123,16 @@ def test_all():
'(((
%
s <
%
s) && (
%
s > (
%
s + 1))) && (
%
s < (
%
s*2)))'
%
(
x
.
name
,
y
.
name
,
y
.
name
,
z
.
name
,
x
.
name
,
z
.
name
)
def
test_bitwise
():
x
=
tvm
.
var
(
'x'
)
y
=
tvm
.
var
(
'y'
)
assert
str
(
x
<<
y
)
==
'shift_left(x, y)'
assert
str
(
x
>>
y
)
==
'shift_right(x, y)'
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
(
~
x
)
==
'bitwise_not(x)'
if
__name__
==
"__main__"
:
test_cast
()
...
...
@@ -137,3 +147,4 @@ if __name__ == "__main__":
test_dtype
()
test_any
()
test_all
()
test_bitwise
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment