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
4fbb7c89
Commit
4fbb7c89
authored
Oct 26, 2018
by
Wei Chen
Committed by
Tianqi Chen
Oct 26, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[RELAY] Add occurs check before unification (#2012)
parent
a0c813b2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
0 deletions
+44
-0
src/relay/pass/type_solver.cc
+5
-0
tests/cpp/relay_pass_type_infer_test.cc
+22
-0
tests/python/relay/test_type_infer.py
+17
-0
No files found.
src/relay/pass/type_solver.cc
View file @
4fbb7c89
...
...
@@ -61,6 +61,11 @@ Type TypeSolver::Unify(const Type& dst, const Type& src) {
// - handle shape pattern matching
TypeNode
*
lhs
=
GetTypeNode
(
dst
);
TypeNode
*
rhs
=
GetTypeNode
(
src
);
// do occur check so we don't create self-referencing structure
if
(
lhs
->
FindRoot
()
==
rhs
->
FindRoot
())
{
return
lhs
->
resolved_type
;
}
if
(
lhs
->
resolved_type
.
as
<
IncompleteTypeNode
>
())
{
MergeFromTo
(
lhs
,
rhs
);
return
rhs
->
resolved_type
;
...
...
tests/cpp/relay_pass_type_infer_test.cc
0 → 100644
View file @
4fbb7c89
#include <gtest/gtest.h>
#include <tvm/tvm.h>
#include <tvm/relay/expr.h>
#include <tvm/relay/type.h>
#include <tvm/relay/pass.h>
TEST
(
Relay
,
SelfReference
)
{
using
namespace
tvm
;
auto
type_a
=
relay
::
TypeVarNode
::
make
(
"a"
,
relay
::
TypeVarNode
::
kType
);
auto
type_b
=
relay
::
TypeVarNode
::
make
(
"b"
,
relay
::
TypeVarNode
::
kType
);
auto
x
=
relay
::
VarNode
::
make
(
"x"
,
type_a
);
auto
f
=
relay
::
FunctionNode
::
make
(
tvm
::
Array
<
relay
::
Var
>
{
x
},
x
,
type_b
,
Array
<
relay
::
TypeVar
>
{});
auto
fx
=
relay
::
CallNode
::
make
(
f
,
Array
<
relay
::
Expr
>
{
x
});
auto
type_fx
=
relay
::
InferType
(
fx
,
relay
::
EnvironmentNode
::
make
(
Map
<
relay
::
GlobalVar
,
relay
::
Function
>
{}));
CHECK_EQ
(
type_fx
->
checked_type
(),
type_a
);
}
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
testing
::
FLAGS_gtest_death_test_style
=
"threadsafe"
;
return
RUN_ALL_TESTS
();
}
tests/python/relay/test_type_infer.py
View file @
4fbb7c89
...
...
@@ -107,6 +107,22 @@ def test_type_args():
assert
sh2
[
0
]
.
value
==
1
assert
sh2
[
1
]
.
value
==
10
def
test_self_reference
():
"""
Program:
def f(x) {
return x;
}
"""
a
=
relay
.
TypeVar
(
"a"
)
x
=
relay
.
var
(
"x"
,
a
)
sb
=
relay
.
ScopeBuilder
()
f
=
relay
.
Function
([
x
],
x
)
fx
=
relay
.
Call
(
f
,
[
x
])
assert
relay
.
ir_pass
.
infer_type
(
x
)
.
checked_type
==
a
assert
relay
.
ir_pass
.
infer_type
(
f
)
.
checked_type
==
relay
.
FuncType
([
a
],
a
)
assert
relay
.
ir_pass
.
infer_type
(
fx
)
.
checked_type
==
a
if
__name__
==
"__main__"
:
test_free_expr
()
test_dual_op
()
...
...
@@ -117,3 +133,4 @@ if __name__ == "__main__":
test_tuple
()
test_free_expr
()
test_type_args
()
test_self_reference
()
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