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

Function SetOpAttrValueScalar

tensorflow/c/eager/c_api.cc:995–1051  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

993
994namespace tensorflow {
995void SetOpAttrValueScalar(TFE_Context* ctx, TFE_Op* op,
996 const tensorflow::AttrValue& default_value,
997 const char* attr_name, TF_Status* status) {
998 switch (default_value.value_case()) {
999 case tensorflow::AttrValue::kS: {
1000 const string& v = default_value.s();
1001 TFE_OpSetAttrString(op, attr_name, v.data(), v.size());
1002 break;
1003 }
1004 case tensorflow::AttrValue::kI:
1005 TFE_OpSetAttrInt(op, attr_name, static_cast<int64_t>(default_value.i()));
1006 break;
1007 case tensorflow::AttrValue::kF:
1008 TFE_OpSetAttrFloat(op, attr_name, default_value.f());
1009 break;
1010 case tensorflow::AttrValue::kB:
1011 TFE_OpSetAttrBool(op, attr_name, default_value.b());
1012 break;
1013 case tensorflow::AttrValue::kType:
1014 TFE_OpSetAttrType(op, attr_name,
1015 static_cast<TF_DataType>(default_value.type()));
1016 break;
1017 case tensorflow::AttrValue::kShape: {
1018 const auto& tensor_shape = default_value.shape();
1019 if (tensor_shape.unknown_rank()) {
1020 TFE_OpSetAttrShape(op, attr_name, nullptr, -1, status);
1021 } else {
1022 const auto num_dims = tensor_shape.dim_size();
1023 std::unique_ptr<int64_t[]> dims(new int64_t[num_dims]);
1024 for (int i = 0; i < num_dims; ++i) {
1025 dims[i] = tensor_shape.dim(i).size();
1026 }
1027 TFE_OpSetAttrShape(op, attr_name, dims.get(), num_dims, status);
1028 }
1029 } break;
1030 case tensorflow::AttrValue::kFunc: {
1031 const auto func_op = GetFunc(ctx, default_value.func(), status);
1032 if (TF_GetCode(status) != TF_OK) return;
1033 // TODO(nareshmodi): TFE_OpSetAttrFunction and TFE_OpSetAttrFunctionList
1034 // require TFE_Op* and just convert it internally a NameAttrValue, so
1035 // consider adding an overload to the C API to make this case easier.
1036 TFE_OpSetAttrFunction(op, attr_name, func_op);
1037 } break;
1038 case tensorflow::AttrValue::kList:
1039 TF_FALLTHROUGH_INTENDED;
1040 case tensorflow::AttrValue::kTensor:
1041 TF_FALLTHROUGH_INTENDED;
1042 case tensorflow::AttrValue::kPlaceholder:
1043 TF_FALLTHROUGH_INTENDED;
1044 case tensorflow::AttrValue::VALUE_NOT_SET:
1045 TF_SetStatus(
1046 status, TF_UNIMPLEMENTED,
1047 tensorflow::strings::StrCat("Unable to get setfor default value: ",
1048 default_value.DebugString())
1049 .data());
1050 }
1051}
1052} // namespace tensorflow

Callers 4

GetFuncFunction · 0.85
SetOpAttrScalarDefaultFunction · 0.85
EvaluateOperationFunction · 0.85
GetFuncFunction · 0.85

Calls 15

TFE_OpSetAttrStringFunction · 0.85
TFE_OpSetAttrIntFunction · 0.85
TFE_OpSetAttrFloatFunction · 0.85
TFE_OpSetAttrBoolFunction · 0.85
TFE_OpSetAttrTypeFunction · 0.85
TFE_OpSetAttrShapeFunction · 0.85
TF_GetCodeFunction · 0.85
TFE_OpSetAttrFunctionFunction · 0.85
TF_SetStatusFunction · 0.85
unknown_rankMethod · 0.80
GetFuncFunction · 0.70
typeMethod · 0.65

Tested by

no test coverage detected