Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions python/python_direct/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ Returns
-------
str
The fusion intermediate representation (IR) as a string.
)")
.def(
"print",
[](Fusion& f) { f.print(std::cout); },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: inconsistent return behavior - print_math and print_kernel both return strings by capturing output in a stringstream, but this new print method prints directly to stdout and returns None. Consider making it consistent:

Suggested change
[](Fusion& f) { f.print(std::cout); },
[](Fusion& f) {
std::stringstream ss;
DebugStreamGuard dsg(ss);
f.print(ss);
return ss.str();
},

R"(
Print the fusion, including transforms, to stdout.

Returns
-------
None
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw other print_*s return a string instead. I personally found it confusing to have to type print twice, but let me know what you think. One option may be to have an __str__.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning a string is nice, so you can search through it in tests.
I thought about renaming print_* to something more clear, since string are returned instead being printed to stdout.

You could map CPP print to __repr__ since it is more verbose than print_math. Then, do print(repr(fd.fusion)).

)")
.def(
"print_kernel",
Expand Down