Customize the printing of namedtuple return#17136
Customize the printing of namedtuple return#17136zasdfgbnm wants to merge 19 commits intopytorch:masterfrom
Conversation
| PyObject *returned_structseq_repr(PyStructSequence *obj) { | ||
| PyTypeObject *typ = Py_TYPE(obj); | ||
| std::stringstream ss; | ||
| ss << typ->tp_name << "(\n"; |
There was a problem hiding this comment.
The default behavior does not have \n here, I added this just because I think it looks better.
|
|
||
| ss << cname << '=' << crepr; | ||
| if (i < num_elements - 1) | ||
| ss << ",\n"; |
There was a problem hiding this comment.
The default behavior has a space instead of a \n here, I changed this just because I think it looks better.
|
Thank you for doing this! Personally, I like your insertion of newlines, too. |
|
Note: This PR also provide code to convert structseq to tuple in C++ side, which would be useful to modify tuple checks to support structseq as tuple(#16813). |
|
Hi Adam @apaszke , Let's discuss your comment #16186 (comment) at here. What do you think is a good printing? I suggest: I mean, the name of the returned type i.e. |
VitalyFedyunin
left a comment
There was a problem hiding this comment.
Everything looks good, except few python ref counters leaks.
|
@pytorchbot rebase this please |
facebook-github-bot
left a comment
There was a problem hiding this comment.
@VitalyFedyunin has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
…dtuple-printing
facebook-github-bot
left a comment
There was a problem hiding this comment.
@VitalyFedyunin has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
LGTM, I will land this as soon as all checks completed. |
|
@zasdfgbnm could you please update quotes to brackets in all includes. This is to follow same style as everywhere is the code. |
) Summary: Currently the following code gives an error on python 2 because `ret` is a structseq which is not a tuple ```python ret = a.max(dim=0) ret1 = torch.max(a, dim=0, out=ret) ``` This PR modify tuple check in python arg parser to allow structseq to be input of operators where tuple is expected, which would make the above code work. Depend on: #17136 Partially fixes: #16813 Pull Request resolved: #17208 Differential Revision: D14280198 Pulled By: VitalyFedyunin fbshipit-source-id: beffebfd3951c4f5c7c8fe99a5847616a89491f3
Fixes #17112
now gives