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
c8259e3e
Commit
c8259e3e
authored
Mar 01, 2019
by
雾雨魔理沙
Committed by
Haichen Shen
Mar 01, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Relay] fix checkwellform (#2705)
* do * address comment
parent
cab5af26
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
5 deletions
+33
-5
src/relay/pass/well_formed.cc
+10
-1
tests/python/relay/test_ir_well_formed.py
+23
-4
No files found.
src/relay/pass/well_formed.cc
View file @
c8259e3e
...
...
@@ -5,6 +5,7 @@
*/
#include <tvm/relay/pass.h>
#include <tvm/relay/expr_functor.h>
#include <tvm/relay/pattern_functor.h>
#include <unordered_set>
namespace
tvm
{
...
...
@@ -12,7 +13,7 @@ namespace relay {
//! brief make sure each Var is bind at most once.
class
WellFormedChecker
:
private
ExprVisitor
{
class
WellFormedChecker
:
private
ExprVisitor
,
PatternVisitor
{
bool
well_formed
=
true
;
std
::
unordered_set
<
Var
,
NodeHash
,
NodeEqual
>
s
;
...
...
@@ -39,6 +40,14 @@ class WellFormedChecker : private ExprVisitor {
CheckWellFormed
(
f
->
body
);
}
void
VisitPattern
(
const
Pattern
&
p
)
final
{
PatternVisitor
::
VisitPattern
(
p
);
}
void
VisitVar
(
const
Var
&
v
)
final
{
Check
(
v
);
}
public
:
bool
CheckWellFormed
(
const
Expr
&
e
)
{
this
->
VisitExpr
(
e
);
...
...
tests/python/relay/test_ir_well_formed.py
View file @
c8259e3e
import
tvm
from
tvm
import
relay
from
tvm.relay.ir_pass
import
well_formed
from
tvm.relay.prelude
import
Prelude
def
test_
well_formed
():
x
=
relay
.
Var
(
'x'
)
def
test_
let
():
x
=
relay
.
Var
(
"x"
)
assert
well_formed
(
x
)
v
=
relay
.
Constant
(
tvm
.
nd
.
array
(
10
))
ty
=
None
...
...
@@ -18,7 +19,7 @@ def test_well_formed():
def
test_tuple
():
x
=
relay
.
Var
(
'x'
)
x
=
relay
.
Var
(
"x"
)
assert
well_formed
(
x
)
v
=
relay
.
Constant
(
tvm
.
nd
.
array
(
10
))
let
=
relay
.
Let
(
x
,
v
,
x
)
...
...
@@ -28,5 +29,23 @@ def test_tuple():
def
test_tuple_get_item
():
t
=
relay
.
Var
(
't'
)
t
=
relay
.
Var
(
"t"
)
assert
well_formed
(
relay
.
TupleGetItem
(
t
,
2
))
def
test_adt
():
mod
=
relay
.
Module
()
p
=
Prelude
(
mod
)
x
=
relay
.
Var
(
"x"
)
s_case
=
relay
.
Clause
(
relay
.
PatternConstructor
(
p
.
s
,
[
relay
.
PatternVar
(
x
)]),
x
)
default_case
=
relay
.
Clause
(
relay
.
PatternVar
(
x
),
x
)
m0
=
relay
.
Match
(
p
.
z
(),
[
default_case
])
m1
=
relay
.
Match
(
p
.
z
(),
[
s_case
,
default_case
])
assert
well_formed
(
m0
)
assert
not
well_formed
(
m1
)
if
__name__
==
"__main__"
:
test_let
()
test_tuple
()
test_tuple_get_item
()
test_adt
()
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