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

Function TEST_F

tensorflow/core/grappler/optimizers/shape_optimizer_test.cc:33–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31class ShapeOptimizerTest : public GrapplerTest {};
32
33TEST_F(ShapeOptimizerTest, OptimizeShapeProduct) {
34 // Set the device to CPU zero, because the shape optimizer will only optimize
35 // Prod to Size when a concrete Size kernel is available.
36 tensorflow::Scope s = tensorflow::Scope::NewRootScope().WithDevice("/cpu:0");
37 Output a = ops::Const(s.WithOpName("a"), 3.14f, {32, 16});
38 Output c = ops::Shape(s.WithOpName("c"), a);
39 Output d = ops::Const(s.WithOpName("d"), 0, {1});
40 ops::ReduceProd::Attrs attrs;
41 Output e = ops::ReduceProd(s.WithOpName("e"), c, d, attrs.KeepDims(false));
42 Output f = ops::ReduceProd(s.WithOpName("f"), c, d, attrs.KeepDims(true));
43
44 GrapplerItem item;
45 item.fetch = {"e", "f"};
46 TF_CHECK_OK(s.ToGraphDef(&item.graph));
47
48 auto tensors_expected = EvaluateNodes(item.graph, item.fetch);
49
50 GraphDef output;
51 ShapeOptimizer optimizer;
52 TF_EXPECT_OK(optimizer.Optimize(nullptr, item, &output));
53
54 int found = 0;
55 for (const NodeDef& node : output.node()) {
56 if (node.name() == "e") {
57 found++;
58 EXPECT_EQ("Size", node.op());
59 EXPECT_EQ("a", node.input(0));
60 } else if (node.name() == "f") {
61 found++;
62 EXPECT_EQ("Prod", node.op());
63 EXPECT_EQ("c", node.input(0));
64 }
65 }
66 EXPECT_EQ(2, found);
67
68 auto tensors_actual = EvaluateNodes(output, item.fetch);
69 EXPECT_NEAR(tensors_expected[0].scalar<int>()(),
70 tensors_actual[0].scalar<int>()(), 0);
71 EXPECT_NEAR(tensors_expected[1].scalar<int>()(),
72 tensors_actual[1].scalar<int>()(), 0);
73}
74
75TEST_F(ShapeOptimizerTest, OptimizeShapeProductMissingKernel) {
76 {

Callers

nothing calls this directly

Calls 15

ReduceProdClass · 0.85
DefaultFunction · 0.85
WithOpNameMethod · 0.80
nameMethod · 0.65
ConstFunction · 0.50
ShapeClass · 0.50
SizeFunction · 0.50
DivFunction · 0.50
WithDeviceMethod · 0.45
KeepDimsMethod · 0.45
ToGraphDefMethod · 0.45
OptimizeMethod · 0.45

Tested by

no test coverage detected