MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / GetOpAttrStruct

Method GetOpAttrStruct

tensorflow/cc/framework/cc_op_gen.cc:693–777  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

691}
692
693string OpInfo::GetOpAttrStruct() const {
694 string struct_fields;
695 string setters;
696 string defaults_static_storage;
697
698 for (int i = 0; i < graph_op_def.attr_size(); ++i) {
699 const auto& attr(graph_op_def.attr(i));
700 const auto& api_def_attr(api_def.attr(i));
701 // If attr will be inferred or it doesn't have a default value, don't
702 // add it to the struct.
703 if ((inferred_input_attrs.find(attr.name()) !=
704 inferred_input_attrs.end()) ||
705 !api_def_attr.has_default_value()) {
706 continue;
707 }
708 const auto entry = AttrTypeName(attr.type());
709 const auto attr_type_name = entry.first;
710 const bool use_const = entry.second;
711 const string camel_case_name = ToCamelCase(api_def_attr.rename_to());
712 const string suffix =
713 (camel_case_name == op_name || camel_case_name == "Attrs") ? "_" : "";
714 const string attr_func_def =
715 strings::StrCat(camel_case_name, suffix, "(", use_const ? "const " : "",
716 attr_type_name, use_const ? "&" : "");
717
718 string attr_comment;
719 if (!api_def_attr.description().empty()) {
720 strings::StrAppend(&attr_comment, api_def_attr.description(), "\n\n");
721 }
722 strings::StrAppend(&attr_comment, "Defaults to ",
723 SummarizeAttrValue(api_def_attr.default_value()), "\n");
724 attr_comment = MakeComment(attr_comment, " ");
725
726 strings::StrAppend(&setters, attr_comment);
727 strings::StrAppend(&setters, " TF_MUST_USE_RESULT Attrs ", attr_func_def,
728 " x) {\n");
729 strings::StrAppend(&setters, " Attrs ret = *this;\n");
730 strings::StrAppend(&setters, " ret.", api_def_attr.rename_to(),
731 "_ = x;\n");
732 strings::StrAppend(&setters, " return ret;\n }\n\n");
733
734 string field_initiliazer;
735 auto& default_value = api_def_attr.default_value();
736 if (default_value.value_case() == AttrValue::kList &&
737 !IsEmptyList(default_value.list())) {
738 // Non-empty lists need static storage for their defaults. Define a
739 // function with static local variable that stores the array.
740 strings::StrAppend(&defaults_static_storage, " static ",
741 attr_type_name, " Default_", api_def_attr.rename_to(),
742 "() {\n");
743 strings::StrAppend(
744 &defaults_static_storage, " static const ",
745 ListElementTypeName(attr.type()), " kStorage[] = ",
746 PrintAttrValue(graph_op_def.name(), api_def_attr.default_value()),
747 ";\n");
748 strings::StrAppend(&defaults_static_storage, " return ",
749 attr_type_name, "(kStorage);\n }\n");
750 // Set the field_initializer to call the defined function.

Callers

nothing calls this directly

Calls 15

AttrTypeNameFunction · 0.85
ToCamelCaseFunction · 0.85
SummarizeAttrValueFunction · 0.85
MakeCommentFunction · 0.85
IsEmptyListFunction · 0.85
ListElementTypeNameFunction · 0.85
PrintAttrValueFunction · 0.85
has_default_valueMethod · 0.80
descriptionMethod · 0.80
listMethod · 0.80
nameMethod · 0.65
typeMethod · 0.65

Tested by

no test coverage detected