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
e0e87222
Commit
e0e87222
authored
Oct 12, 2016
by
tqchen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
checkin basic expr
parent
eef4a690
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
127 additions
and
0 deletions
+127
-0
python/tvm/__init__.py
+3
-0
python/tvm/expr.py
+90
-0
python/tvm/op.py
+26
-0
tests/python/test_basic.py
+8
-0
No files found.
python/tvm/__init__.py
View file @
e0e87222
"""Init proptype of the TVM"""
from
__future__
import
absolute_import
as
_abs
from
.op
import
*
python/tvm/expr.py
0 → 100644
View file @
e0e87222
"""Base class of symbolic expression"""
from
__future__
import
absolute_import
as
_abs
from
numbers
import
Number
as
_Number
from
.
import
op
as
_op
class
Expr
(
object
):
"""Base class of expression."""
def
children
(
self
):
"""All expr must define this.
Returns
-------
children : generator of children
"""
return
()
def
__add__
(
self
,
other
):
return
BinaryOpExpr
(
_op
.
add
,
self
,
other
)
def
__radd__
(
self
,
other
):
return
self
.
__add__
(
other
)
def
__sub__
(
self
,
other
):
return
BinaryOpExpr
(
_op
.
sub
,
self
,
other
)
def
__rsub__
(
self
,
other
):
return
BinaryOpExpr
(
_op
.
sub
,
other
,
self
)
def
__mul__
(
self
,
other
):
return
BinaryOpExpr
(
_op
.
mul
,
self
,
other
)
def
__rmul__
(
self
,
other
):
return
BinaryOpExpr
(
_op
.
mul
,
other
,
self
)
def
__div__
(
self
,
other
):
return
BinaryOpExpr
(
_op
.
div
,
self
,
other
)
def
__rdiv__
(
self
,
other
):
return
BinaryOpExpr
(
_op
.
div
,
self
,
other
)
def
__truediv__
(
self
,
other
):
return
self
.
__div__
(
other
)
def
__rtruediv__
(
self
,
other
):
return
self
.
__rdiv__
(
other
)
def
__neg__
(
self
):
return
self
.
__mul__
(
-
1
)
def
_symbol
(
value
):
"""Convert a value to expression."""
if
isinstance
(
value
,
Expr
):
return
value
elif
isinstance
(
value
,
_Number
):
return
ConstExpr
(
value
)
else
:
raise
TypeError
(
"type
%
s not supported"
%
str
(
type
(
other
)))
class
ConstExpr
(
Expr
):
"""Constant expression."""
def
__init__
(
self
,
value
):
assert
isinstance
(
value
,
_Number
)
self
.
value
=
value
class
BinaryOpExpr
(
Expr
):
"""Binary operator expression."""
def
__init__
(
self
,
op
,
lhs
,
rhs
):
self
.
op
=
op
self
.
lhs
=
_symbol
(
lhs
)
self
.
rhs
=
_symbol
(
rhs
)
def
children
(
self
):
return
(
self
.
lhs
,
self
.
rhs
)
_op
.
binary_op_cls
=
BinaryOpExpr
class
UnaryOpExpr
(
Expr
):
"""Unary operator expression."""
def
__init__
(
self
,
op
,
src
):
self
.
op
=
op
self
.
src
=
_symbol
(
src
)
def
children
(
self
):
return
(
self
.
src
)
python/tvm/op.py
0 → 100644
View file @
e0e87222
from
__future__
import
absolute_import
as
_abs
_binary_op_cls
=
None
class
BinaryOp
(
object
):
"""Base class of binary operator"""
def
__call__
(
self
,
lhs
,
rhs
):
return
_binary_op_cls
(
self
,
lhs
,
rhs
)
class
AddOp
(
BinaryOp
):
pass
class
SubOp
(
BinaryOp
):
pass
class
MulOp
(
BinaryOp
):
pass
class
DivOp
(
BinaryOp
):
pass
add
=
AddOp
()
sub
=
SubOp
()
mul
=
MulOp
()
div
=
DivOp
()
tests/python/test_basic.py
View file @
e0e87222
import
tvm
from
tvm
import
expr
def
test_const
():
x
=
expr
.
ConstExpr
(
1
)
x
+
1
print
x
test_const
()
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