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

Function TEST

tensorflow/core/common_runtime/function_test.cc:1889–1932  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1887} // end namespace
1888
1889TEST(OptimizationTest, RemoveDeadNodes) {
1890 auto T = DT_INT32;
1891 auto func = FDH::Define(
1892 // Name
1893 "F",
1894 // Args
1895 {"x: int32"},
1896 // Return values
1897 {"y: int32"},
1898 // Attrs
1899 {},
1900 // Nodes
1901 {// a = Square<T>(x)
1902 {{"a"}, "Square", {"x"}, {{"T", T}}},
1903 // 1
1904 FDH::Const("o", 1),
1905 // A bunch of extra arithmetic that y doesn't depend on
1906 {{"x1"}, "Add", {"o", "o"}, {{"T", T}}},
1907 {{"x2"}, "Mul", {"a", "x1"}, {{"T", T}}},
1908 {{"x3"}, "Mul", {"x1", "x2"}, {{"T", T}}},
1909 // A stateful node.
1910 {{"keep_me"}, "RandomUniform", {"o"}, {{"T", T}, {"dtype", DT_FLOAT}}},
1911 // y = Add<T>(a, o)
1912 {{"y"}, "Add", {"a", "o"}, {{"T", T}}}});
1913
1914 GraphDef expected;
1915 {
1916 Scope s = Scope::DisabledShapeInferenceScope();
1917 auto x = ops::_Arg(s.WithOpName("x"), DT_INT32, 0);
1918 auto o = ops::Const(s.WithOpName("o"), 1);
1919 auto keep_me = ops::RandomUniform(s.WithOpName("keep_me"), {o}, DT_FLOAT);
1920 auto x1 = ops::Add(s.WithOpName("x1"), o, o);
1921 auto a = ops::Square(s.WithOpName("a"), x);
1922 auto y = ops::Add(s.WithOpName("y"), a, o);
1923 auto x2 = ops::Mul(s.WithOpName("x2"), a, x1);
1924 auto x3 = ops::Mul(s.WithOpName("x3"), x1, x2);
1925 auto ret = ops::_Retval(s.WithOpName("y_RetVal"), y, 0);
1926 TF_ASSERT_OK(s.ToGraphDef(&expected));
1927 }
1928 TF_EXPECT_GRAPH_EQ(expected, Optimize(DoNothing, func));
1929
1930 // TODO(zhifengc): Comes up another test case.
1931 TF_EXPECT_GRAPH_EQ(expected, Optimize(::tensorflow::RemoveDeadNodes, func));
1932}
1933
1934TEST(OptimizationTest, RemoveIdentityNodes_Ref) {
1935 auto T = DT_FLOAT;

Callers

nothing calls this directly

Calls 15

PartialTensorShapeClass · 0.85
RemoveListArrayConverterFunction · 0.85
RemoveIdentityNodesFunction · 0.85
WithOpNameMethod · 0.80
OptimizeFunction · 0.70
ConstFunction · 0.50
RandomUniformFunction · 0.50
AddFunction · 0.50
SquareFunction · 0.50
MulFunction · 0.50
TensorShapeClass · 0.50
VariableClass · 0.50

Tested by

no test coverage detected