| 927 | } |
| 928 | |
| 929 | string OpInfo::GetConstructorBody() const { |
| 930 | const string scope_str = arg_names[0]; |
| 931 | |
| 932 | string body; |
| 933 | string return_on_error = |
| 934 | strings::StrCat("if (!", scope_str, ".ok()) return;"); |
| 935 | |
| 936 | strings::StrAppend(&body, " ", return_on_error, "\n"); |
| 937 | |
| 938 | for (int i = 0; i < graph_op_def.input_arg_size(); ++i) { |
| 939 | const auto& arg(graph_op_def.input_arg(i)); |
| 940 | const auto& api_def_arg(api_def.in_arg(i)); |
| 941 | strings::StrAppend( |
| 942 | &body, " auto _", api_def_arg.rename_to(), " = ::tensorflow::ops::", |
| 943 | ArgIsList(arg) ? "AsNodeOutList" : "AsNodeOut", "(", scope_str, ", ", |
| 944 | AvoidCPPKeywords(api_def_arg.rename_to()), ");\n"); |
| 945 | strings::StrAppend(&body, " ", return_on_error, "\n"); |
| 946 | } |
| 947 | |
| 948 | strings::StrAppend(&body, " ::tensorflow::Node* ret;\n"); |
| 949 | strings::StrAppend(&body, " const auto unique_name = ", scope_str, |
| 950 | ".GetUniqueNameForOp(\"", op_name, "\");\n"); |
| 951 | strings::StrAppend( |
| 952 | &body, " auto builder = ::tensorflow::NodeBuilder(unique_name, \"", |
| 953 | graph_op_def.name(), "\")\n"); |
| 954 | const string spaces = " "; |
| 955 | for (int i = 0; i < api_def.in_arg_size(); ++i) { |
| 956 | const auto& arg(api_def.in_arg(i)); |
| 957 | strings::StrAppend(&body, spaces, ".Input(_", arg.rename_to(), ")\n"); |
| 958 | } |
| 959 | for (int i = 0; i < api_def.attr_size(); ++i) { |
| 960 | const auto& graph_attr(graph_op_def.attr(i)); |
| 961 | const auto& api_def_attr(api_def.attr(i)); |
| 962 | if (inferred_input_attrs.find(api_def_attr.name()) != |
| 963 | inferred_input_attrs.end()) { |
| 964 | continue; |
| 965 | } |
| 966 | const string attr_name = |
| 967 | api_def_attr.has_default_value() |
| 968 | ? strings::StrCat("attrs.", api_def_attr.rename_to(), "_") |
| 969 | : AvoidCPPKeywords(api_def_attr.rename_to()); |
| 970 | strings::StrAppend(&body, spaces, ".Attr(\"", graph_attr.name(), "\", ", |
| 971 | attr_name, ")\n"); |
| 972 | } |
| 973 | strings::StrAppend(&body, " ;\n"); |
| 974 | strings::StrAppend(&body, " ", scope_str, ".UpdateBuilder(&builder);\n"); |
| 975 | strings::StrAppend(&body, " ", scope_str, ".UpdateStatus(builder.Finalize(", |
| 976 | scope_str, ".graph(), &ret));\n"); |
| 977 | strings::StrAppend(&body, " ", return_on_error, "\n"); |
| 978 | strings::StrAppend(&body, " ", scope_str, ".UpdateStatus(", scope_str, |
| 979 | ".DoShapeInference(ret));\n"); |
| 980 | |
| 981 | GetOutput(&body); |
| 982 | return body; |
| 983 | } |
| 984 | |
| 985 | void OpInfo::WriteClassDef(WritableFile* cc) const { |
| 986 | string class_def; |
nothing calls this directly
no test coverage detected