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
24e51abc
Commit
24e51abc
authored
Oct 19, 2018
by
Josh Pollock
Committed by
Tianqi Chen
Oct 19, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Relay] Nullable Type Alpha Equality (#1906)
parent
f2b30f9e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
7 deletions
+36
-7
src/relay/pass/alpha_eq.cc
+9
-7
tests/python/relay/test_pass_alpha_equal.py
+27
-0
No files found.
src/relay/pass/alpha_eq.cc
View file @
24e51abc
...
...
@@ -193,6 +193,12 @@ struct TypeAlphaEq : TypeVisitor<const Type&> {
};
bool
AlphaEqual
(
const
Type
&
t1
,
const
Type
&
t2
)
{
if
(
t1
.
defined
()
!=
t2
.
defined
())
return
false
;
if
(
!
t1
.
defined
())
return
true
;
TypeAlphaEq
aeq
;
aeq
.
VisitType
(
t1
,
t2
);
return
aeq
.
equal
;
...
...
@@ -373,15 +379,11 @@ struct AlphaEq : ExprFunctor<void(const Expr&, const Expr&)> {
private
:
void
MergeVarDecl
(
const
Var
&
var1
,
const
Var
&
var2
)
{
if
(
var1
->
type_annotation
.
defined
()
!=
var2
->
type_annotation
.
defined
())
{
equal
=
false
;
return
;
}
if
(
var1
->
type_annotation
.
defined
()
&&
!
AlphaEqual
(
var1
->
type_annotation
,
var2
->
type_annotation
))
{
equal
=
false
;
equal
=
equal
&&
AlphaEqual
(
var1
->
type_annotation
,
var2
->
type_annotation
);
if
(
!
equal
)
{
return
;
}
eq_map
.
Set
(
var1
,
var2
);
}
};
...
...
tests/python/relay/test_pass_alpha_equal.py
View file @
24e51abc
...
...
@@ -187,6 +187,25 @@ def test_var_alpha_equal():
assert
alpha_equal
(
l1
,
l2
)
assert
not
alpha_equal
(
l1
,
l3
)
# type annotations
tt1
=
relay
.
TensorType
([],
"int32"
)
tt2
=
relay
.
TensorType
([],
"int32"
)
tt3
=
relay
.
TensorType
([],
"int64"
)
v3
=
relay
.
Var
(
"v3"
,
tt1
)
v4
=
relay
.
Var
(
"v4"
,
tt2
)
v5
=
relay
.
Var
(
"v5"
,
tt3
)
l4
=
relay
.
Let
(
v3
,
convert
(
1
),
v3
)
l5
=
relay
.
Let
(
v4
,
convert
(
1
),
v4
)
l6
=
relay
.
Let
(
v5
,
convert
(
1
),
v5
)
# same annotations
assert
alpha_equal
(
l4
,
l5
)
# different annotations
assert
not
alpha_equal
(
l4
,
l6
)
# one null annotation
assert
not
alpha_equal
(
l1
,
l4
)
def
test_global_var_alpha_equal
():
v1
=
relay
.
GlobalVar
(
"v1"
)
...
...
@@ -307,6 +326,14 @@ def test_function_alpha_equal():
tupled_example
=
relay
.
Function
(
basic_args
,
relay
.
Tuple
([
v3
,
v4
]),
tt3
)
assert
not
alpha_equal
(
func
,
tupled_example
)
# nullable
no_ret_type
=
relay
.
Function
(
basic_args
,
v4
,
None
,
[
tp1
,
tp2
])
# both null
assert
alpha_equal
(
no_ret_type
,
no_ret_type
)
# one null
assert
not
alpha_equal
(
func
,
no_ret_type
)
assert
not
alpha_equal
(
no_ret_type
,
func
)
def
test_call_alpha_equal
():
v1
=
relay
.
Var
(
"v1"
)
...
...
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