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
befd8c1e
Commit
befd8c1e
authored
Jun 04, 2019
by
ziheng
Committed by
Tianqi Chen
Jun 04, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[LANG] Comparison operators support for Imm expressions (#3283)
parent
072f8cc7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
12 deletions
+35
-12
python/tvm/expr.py
+10
-0
python/tvm/relay/quantize/quantize.py
+5
-8
src/relay/op/type_relations.cc
+4
-4
tests/python/unittest/test_lang_basic.py
+9
-0
tests/python/unittest/test_lang_container.py
+7
-0
No files found.
python/tvm/expr.py
View file @
befd8c1e
...
...
@@ -349,6 +349,16 @@ class StringImm(ConstExpr):
self
.
__init_handle_by_constructor__
(
_make
.
StringImm
,
value
)
def
__eq__
(
self
,
other
):
if
isinstance
(
other
,
ConstExpr
):
return
self
.
value
==
other
.
value
return
self
.
value
==
other
def
__ne__
(
self
,
other
):
if
isinstance
(
other
,
ConstExpr
):
return
self
.
value
!=
other
.
value
return
self
.
value
!=
other
@register_node
class
Cast
(
Expr
):
...
...
python/tvm/relay/quantize/quantize.py
View file @
befd8c1e
...
...
@@ -22,7 +22,6 @@ import numpy as np
from
.
import
_quantize
from
..
import
expr
as
_expr
from
..
import
ir_pass
as
_ir_pass
from
..
import
transform
as
_transform
from
..
import
op
as
_op
from
...
import
make
as
_make
from
..base
import
NodeBase
,
register_relay_node
...
...
@@ -301,8 +300,6 @@ def optimize(func, params=None):
"FoldConstant"
,
"CanonicalizeOps"
]
cfg
=
_transform
.
build_config
(
required_pass
=
opt_passes
)
if
params
:
name_dict
=
{}
for
arg
in
func
.
params
:
...
...
@@ -321,25 +318,25 @@ def optimize(func, params=None):
bind_dict
[
arg
]
=
_expr
.
const
(
v
)
func
=
_expr
.
bind
(
func
,
bind_dict
)
if
"SimplifyInference"
in
cfg
.
required_pas
s
:
if
"SimplifyInference"
in
opt_passe
s
:
func
=
_ir_pass
.
infer_type
(
func
)
func
=
_ir_pass
.
simplify_inference
(
func
)
if
"FoldConstant"
in
cfg
.
required_pas
s
:
if
"FoldConstant"
in
opt_passe
s
:
func
=
_ir_pass
.
fold_constant
(
func
)
if
"FoldScaleAxis"
in
cfg
.
required_pas
s
:
if
"FoldScaleAxis"
in
opt_passe
s
:
func
=
_ir_pass
.
infer_type
(
func
)
func
=
_ir_pass
.
backward_fold_scale_axis
(
func
)
func
=
_ir_pass
.
infer_type
(
func
)
func
=
_ir_pass
.
forward_fold_scale_axis
(
func
)
func
=
_ir_pass
.
fold_constant
(
func
)
if
"CanonicalizeOps"
in
cfg
.
required_pas
s
:
if
"CanonicalizeOps"
in
opt_passe
s
:
func
=
_ir_pass
.
infer_type
(
func
)
func
=
_ir_pass
.
canonicalize_ops
(
func
)
if
"FoldConstant"
in
cfg
.
required_pas
s
:
if
"FoldConstant"
in
opt_passe
s
:
func
=
_ir_pass
.
fold_constant
(
func
)
return
func
...
...
src/relay/op/type_relations.cc
View file @
befd8c1e
...
...
@@ -108,8 +108,8 @@ bool BroadcastRel(const Array<Type>& types,
const
Attrs
&
attrs
,
const
TypeReporter
&
reporter
)
{
CHECK_EQ
(
types
.
size
(),
3
);
DLOG
(
INFO
)
<<
"In1:"
<<
types
[
0
]
<<
",In2:"
<<
types
[
1
]
<<
",Out:"
<<
types
[
2
]
<<
std
::
endl
;
//
DLOG(INFO) << "In1:" << types[0] << ",In2:" << types[1]
//
<< ",Out:" << types[2] << std::endl;
if
(
auto
t0
=
ToTensorType
(
types
[
0
]))
{
if
(
auto
t1
=
ToTensorType
(
types
[
1
]))
{
CHECK_EQ
(
t0
->
dtype
,
t1
->
dtype
);
...
...
@@ -126,8 +126,8 @@ bool BroadcastCompRel(const Array<Type>& types,
const
Attrs
&
attrs
,
const
TypeReporter
&
reporter
)
{
CHECK_EQ
(
types
.
size
(),
3
);
DLOG
(
INFO
)
<<
"In1:"
<<
types
[
0
]
<<
",In2:"
<<
types
[
1
]
<<
",Out:"
<<
types
[
2
]
<<
std
::
endl
;
//
DLOG(INFO) << "In1:" << types[0] << ",In2:" << types[1]
//
<< ",Out:" << types[2] << std::endl;
if
(
auto
t0
=
ToTensorType
(
types
[
0
]))
{
if
(
auto
t1
=
ToTensorType
(
types
[
1
]))
{
CHECK_EQ
(
t0
->
dtype
,
t1
->
dtype
);
...
...
tests/python/unittest/test_lang_basic.py
View file @
befd8c1e
...
...
@@ -163,6 +163,14 @@ def test_equality():
d
=
(
c
!=
c
)
assert
not
d
def
test_equality_string_imm
():
x
=
'a'
y
=
tvm
.
make
.
StringImm
(
x
)
x
==
y
.
value
x
==
y
if
__name__
==
"__main__"
:
test_cast
()
test_attr
()
...
...
@@ -178,3 +186,4 @@ if __name__ == "__main__":
test_all
()
test_bitwise
()
test_equality
()
test_equality_string_imm
()
tests/python/unittest/test_lang_container.py
View file @
befd8c1e
...
...
@@ -65,9 +65,16 @@ def test_map_save_load_json():
assert
(
dd
==
{
"a"
:
2
,
"b"
:
3
})
def
test_in_container
():
arr
=
tvm
.
convert
([
'a'
,
'b'
,
'c'
])
assert
'a'
in
arr
assert
tvm
.
make
.
StringImm
(
'a'
)
in
arr
assert
'd'
not
in
arr
if
__name__
==
"__main__"
:
test_str_map
()
test_array
()
test_map
()
test_array_save_load_json
()
test_map_save_load_json
()
test_in_container
()
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