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

Function TEST

tensorflow/core/framework/graph_to_functiondef_test.cc:54–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54TEST(GraphToFunctionDefTest, Basics) {
55 Scope root = Scope::NewRootScope().ExitOnError();
56 auto a = ops::_Arg(root.WithOpName("A"), DT_FLOAT, 0);
57 auto b = ops::_Arg(root.WithOpName("B"), DT_FLOAT, 1);
58 auto c = ops::_Arg(root.WithOpName("C"), DT_FLOAT, 2);
59 auto d = ops::Add(root.WithOpName("D"), a, b);
60 auto e = ops::Add(root.WithOpName("b"), d, c);
61 auto f = ops::Neg(root.WithOpName("h"), e);
62 auto g = ops::AddN(root.WithOpName("G"), std::initializer_list<Output>{e, f});
63 auto h = ops::_Retval(root.WithOpName("H"), g, 0);
64
65 GraphDef graph_def;
66 TF_EXPECT_OK(root.ToGraphDef(&graph_def));
67
68 std::unique_ptr<Graph> graph(new Graph(OpRegistry::Global()));
69 GraphConstructorOptions options;
70 TF_EXPECT_OK(ConvertGraphDefToGraph(options, graph_def, graph.get()));
71
72 FunctionDef fdef;
73 TF_EXPECT_OK(GraphToFunctionDef(*graph, "test_fn", &fdef));
74
75 FunctionDef fdef_expected = FunctionDefHelper::Create(
76 "test_fn", // function name
77 {"a: float", "b: float", "c: float"}, // inputs
78 {"h_0: float"}, // outputs
79 {}, // attrs
80 {
81 // nodes in the function body
82 {{"D"}, "Add", {"a", "b"}, {{"T", DT_FLOAT}}},
83 {{"b_0"}, "Add", {"D:z:0", "c"}, {{"T", DT_FLOAT}}},
84 {{"h"}, "Neg", {"b_0:z:0"}, {{"T", DT_FLOAT}}},
85 {{"G"}, "AddN", {"b_0:z:0", "h:y:0"}, {{"N", 2}, {"T", DT_FLOAT}}},
86 },
87 {{"h_0", "G:sum:0"}}); // return values
88
89 string diff;
90 bool fdefs_equal =
91 EqualFunctionDef(fdef_expected, RemoveDebugInfo(fdef), &diff);
92 EXPECT_TRUE(fdefs_equal) << diff;
93}
94
95// Regression test for a crash if there was a control edge to a _Retval node.
96TEST(GraphToFunctionDefTest, ControlDependencies) {

Callers

nothing calls this directly

Calls 14

ConvertGraphDefToGraphFunction · 0.85
RemoveDebugInfoFunction · 0.85
ExitOnErrorMethod · 0.80
WithOpNameMethod · 0.80
GraphToFunctionDefFunction · 0.70
EqualFunctionDefFunction · 0.70
nameMethod · 0.65
AddFunction · 0.50
NegFunction · 0.50
AddNFunction · 0.50
CreateFunction · 0.50
ToGraphDefMethod · 0.45

Tested by

no test coverage detected