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
fed1c08e
Commit
fed1c08e
authored
Apr 25, 2019
by
Josh Pollock
Committed by
Tianqi Chen
Apr 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Relay][Text Format] Fix Pretty Printing Annotations (#3041)
parent
cdc9e85c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
12 deletions
+14
-12
src/relay/ir/pretty_printer.cc
+13
-11
tests/python/relay/test_ir_text_printer.py
+1
-1
No files found.
src/relay/ir/pretty_printer.cc
View file @
fed1c08e
...
...
@@ -156,14 +156,19 @@ class PrettyPrinter :
*/
Doc
PrintOptionalInfo
(
const
Expr
&
expr
)
{
Doc
doc
;
//
additional information in comment.
if
(
annotate_
!
=
nullptr
)
{
return
doc
<<
" /* "
<<
annotate_
(
expr
)
<<
" */"
;
}
else
if
(
expr
->
checked_type_
.
defined
())
{
return
doc
<<
" /* ty="
<<
Print
(
expr
->
checked_type
())
<<
" */"
;
//
default annotations
if
(
annotate_
=
=
nullptr
)
{
if
((
expr
.
as
<
ConstantNode
>
()
||
expr
.
as
<
CallNode
>
())
&&
expr
->
checked_type_
.
defined
())
{
doc
<<
" /* ty="
<<
Print
(
expr
->
checked_type
())
<<
" */"
;
}
}
else
{
return
doc
;
std
::
string
annotated_expr
=
annotate_
(
expr
);
if
(
annotated_expr
!=
""
)
{
doc
<<
annotated_expr
;
}
}
return
doc
;
}
// indent a new body
...
...
@@ -361,9 +366,7 @@ class PrettyPrinter :
printed_expr
=
VisitExpr
(
expr
);
}
if
(
expr
.
as
<
CallNode
>
())
{
printed_expr
<<
PrintOptionalInfo
(
expr
);
}
printed_expr
<<
PrintOptionalInfo
(
expr
);
// add expr to doc
if
(
expr
.
as
<
VarNode
>
())
{
...
...
@@ -409,8 +412,7 @@ class PrettyPrinter :
}
// default fall-back, record it as meta node.
Doc
doc
;
return
doc
<<
Print
(
GetRef
<
NodeRef
>
(
op
),
true
)
<<
PrintOptionalInfo
(
GetRef
<
Expr
>
(
op
));
return
doc
<<
Print
(
GetRef
<
NodeRef
>
(
op
),
true
);
}
Doc
VisitExpr_
(
const
TupleNode
*
op
)
final
{
...
...
tests/python/relay/test_ir_text_printer.py
View file @
fed1c08e
...
...
@@ -52,7 +52,7 @@ def test_env():
assert
"def @myf"
in
str
(
env
)
assert
"add(
%0
,
%0
) /* ty=float32 */"
in
text
assert
"add(
%0
,
%0
) /* ty=float32 */"
in
str
(
env
)
show
(
env
.
astext
(
annotate
=
lambda
x
:
str
(
x
.
checked_type
.
dtype
)))
show
(
env
.
astext
(
annotate
=
lambda
x
:
str
(
x
.
checked_type
.
dtype
)
if
type
(
x
)
==
relay
.
Call
else
""
))
show
(
text
)
...
...
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