| 769 | } |
| 770 | |
| 771 | void GenPythonOp::AddOutputGlobals() { |
| 772 | // Prepare a NamedTuple type to hold the outputs, if there are multiple |
| 773 | if (num_outs_ > 1) { |
| 774 | // Prepare the list of output names |
| 775 | std::vector<string> out_names(num_outs_); |
| 776 | for (int i = 0; i < num_outs_; ++i) { |
| 777 | if (!api_def_.out_arg(i).rename_to().empty()) { |
| 778 | out_names[i] = api_def_.out_arg(i).rename_to(); |
| 779 | } else { |
| 780 | out_names[i] = strings::StrCat("output", i); |
| 781 | } |
| 782 | } |
| 783 | string out_names_list = |
| 784 | strings::StrCat("[\"", absl::StrJoin(out_names, "\", \""), "\"]"); |
| 785 | |
| 786 | // Provide the output names as a Python list |
| 787 | string lower_op_name_outputs = |
| 788 | strings::StrCat("_", function_name_, "_outputs"); |
| 789 | const string outputs_prefix = strings::StrCat(lower_op_name_outputs, " = "); |
| 790 | strings::StrAppend(&prelude_, "\n", |
| 791 | WordWrap(outputs_prefix, out_names_list, kRightMargin), |
| 792 | "\n"); |
| 793 | |
| 794 | strings::StrAppend(&prelude_, "_", op_def_.name(), |
| 795 | "Output = _collections.namedtuple(\n"); |
| 796 | const string tuple_type_prefix = " "; |
| 797 | const string tuple_type_suffix = strings::StrCat( |
| 798 | "\"", op_def_.name(), "\", ", lower_op_name_outputs, ")"); |
| 799 | strings::StrAppend( |
| 800 | &prelude_, WordWrap(tuple_type_prefix, tuple_type_suffix, kRightMargin), |
| 801 | "\n\n"); |
| 802 | } |
| 803 | strings::StrAppend(&prelude_, "\n"); |
| 804 | } |
| 805 | |
| 806 | void GenPythonOp::AddDocStringOutputs() { |
| 807 | std::vector<string> output_type_string; |