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

Method AddDocStringAttrs

tensorflow/python/framework/python_op_gen_internal.cc:695–764  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

693}
694
695void GenPythonOp::AddDocStringAttrs() {
696 for (const string& name : attrs_) {
697 const auto& attr = *FindAttr(name, op_def_);
698 const auto& api_def_attr = *FindAttr(name, api_def_);
699 string desc =
700 strings::StrCat(AvoidPythonReserved(api_def_attr.rename_to()), ": ");
701
702 static const char* const kAttrTypeName[][2] = {
703 {"string", "`string`"},
704 {"list(string)", "list of `strings`"},
705 {"int", "`int`"},
706 {"list(int)", "list of `ints`"},
707 {"float", "`float`"},
708 {"list(float)", "list of `floats`"},
709 {"bool", "`bool`"},
710 {"list(bool)", "list of `bools`"},
711 {"type", "`tf.DType`"},
712 {"list(type)", "list of `tf.DTypes`"},
713 {"shape", "`tf.TensorShape` or list of `ints`"},
714 {"list(shape)",
715 "list of shapes (each a `tf.TensorShape` or list of `ints`)"},
716 {"tensor", "`tf.TensorProto`"},
717 {"list(tensor)", "list of `tf.TensorProto` objects"},
718 {"func", "function decorated with @Defun"},
719 {"list(func)", "list of functions decorated with @Defun"},
720 };
721 for (size_t i = 0; i < TF_ARRAYSIZE(kAttrTypeName); ++i) {
722 if (attr.type() == kAttrTypeName[i][0]) {
723 string s;
724 if (api_def_attr.has_default_value()) {
725 s = strings::StrCat("optional ", kAttrTypeName[i][1]);
726 } else {
727 s = kAttrTypeName[i][1];
728 }
729 if (s[0] == 'o' || (s[0] == '`' && (s[1] == 'i' || s[1] == 'o'))) {
730 strings::StrAppend(&desc, "An ", s);
731 } else {
732 strings::StrAppend(&desc, "A ", s);
733 }
734 break;
735 }
736 }
737
738 if (attr.has_allowed_values()) {
739 strings::StrAppend(&desc, " from: `",
740 AttrListToPython(attr.allowed_values()), "`");
741 }
742
743 if (attr.has_minimum()) {
744 if (attr.type() == "int") {
745 strings::StrAppend(&desc, " that is `>= ", attr.minimum(), "`");
746 } else if (attr.minimum() > 0) {
747 strings::StrAppend(&desc, " that has length `>= ", attr.minimum(), "`");
748 }
749 }
750
751 strings::StrAppend(&desc, ".");
752

Callers

nothing calls this directly

Calls 14

AvoidPythonReservedFunction · 0.85
AttrListToPythonFunction · 0.85
AttrValueToPythonFunction · 0.85
AppendWithinWidthFunction · 0.85
has_default_valueMethod · 0.80
minimumMethod · 0.80
descriptionMethod · 0.80
FindAttrFunction · 0.70
IndentFunction · 0.70
typeMethod · 0.65
StrCatFunction · 0.50
StrAppendFunction · 0.50

Tested by

no test coverage detected