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

Function TF_NewWhile

tensorflow/c/c_api.cc:1917–1967  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1915} // namespace
1916
1917TF_WhileParams TF_NewWhile(TF_Graph* g, TF_Output* inputs, int ninputs,
1918 TF_Status* status) {
1919#if defined(IS_MOBILE_PLATFORM) || defined(IS_SLIM_BUILD)
1920 status->status = tensorflow::errors::Unimplemented(
1921 "Creating while loops is not supported on mobile. File a bug at "
1922 "https://github.com/tensorflow/tensorflow/issues if this feature is "
1923 "important to you");
1924 return EmptyWhileParams();
1925#else
1926 if (ninputs == 0) {
1927 status->status =
1928 InvalidArgument("TF_NewWhile() must be passed at least one input");
1929 return EmptyWhileParams();
1930 }
1931
1932 TF_Graph* cond_graph = TF_NewGraph();
1933 TF_Graph* body_graph = TF_NewGraph();
1934 cond_graph->parent = g;
1935 cond_graph->parent_inputs = inputs;
1936 body_graph->parent = g;
1937 body_graph->parent_inputs = inputs;
1938
1939 TF_Output* cond_inputs = new TF_Output[ninputs];
1940 TF_Output cond_output = {nullptr, -1};
1941 TF_Output* body_inputs = new TF_Output[ninputs];
1942 TF_Output* body_outputs = new TF_Output[ninputs];
1943 for (int i = 0; i < ninputs; ++i) body_outputs[i] = {nullptr, -1};
1944 const char* name = nullptr;
1945
1946 for (int i = 0; i < ninputs; ++i) {
1947 // TODO(skyewm): prefix names with underscore (requires some plumbing)
1948 if (!CreateInput(inputs[i], cond_graph, StrCat("cond_input", i).c_str(),
1949 &cond_inputs[i], status)) {
1950 break;
1951 }
1952 if (!CreateInput(inputs[i], body_graph, StrCat("body_input", i).c_str(),
1953 &body_inputs[i], status)) {
1954 break;
1955 }
1956 }
1957
1958 TF_WhileParams params = {ninputs, cond_graph, cond_inputs, cond_output,
1959 body_graph, body_inputs, body_outputs, name};
1960
1961 if (TF_GetCode(status) != TF_OK) {
1962 FreeWhileResources(&params);
1963 return EmptyWhileParams();
1964 }
1965 return params;
1966#endif // defined(IS_MOBILE_PLATFORM) || defined(IS_SLIM_BUILD)
1967}
1968
1969#if !defined(IS_MOBILE_PLATFORM) && !defined(IS_SLIM_BUILD)
1970namespace {

Callers 4

InitMethod · 0.85
TEST_FFunction · 0.85
TEST_FFunction · 0.85

Calls 9

UnimplementedFunction · 0.85
EmptyWhileParamsFunction · 0.85
InvalidArgumentFunction · 0.85
TF_NewGraphFunction · 0.85
TF_GetCodeFunction · 0.85
FreeWhileResourcesFunction · 0.85
c_strMethod · 0.80
CreateInputFunction · 0.70
StrCatFunction · 0.50

Tested by 3

InitMethod · 0.68
TEST_FFunction · 0.68
TEST_FFunction · 0.68