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

Function TEST

tensorflow/core/framework/shape_inference_testutil_test.cc:69–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67} // namespace
68
69TEST(ShapeInferenceTestutilTest, Failures) {
70 auto fn_copy_input_0 = [](InferenceContext* c) {
71 c->set_output(0, c->input(0));
72 return Status::OK();
73 };
74 auto fn_copy_input_2 = [](InferenceContext* c) {
75 c->set_output(0, c->input(2));
76 return Status::OK();
77 };
78 auto fn_output_unknown_shapes = [](InferenceContext* c) {
79 for (int i = 0; i < c->num_outputs(); ++i) {
80 c->set_output(i, c->UnknownShape());
81 }
82 return Status::OK();
83 };
84 auto fn_output_1_2 = [](InferenceContext* c) {
85 c->set_output(0, c->Matrix(1, 2));
86 return Status::OK();
87 };
88 auto fn_output_u_2 = [](InferenceContext* c) {
89 c->set_output(0, c->Matrix(InferenceContext::kUnknownDim, 2));
90 return Status::OK();
91 };
92 const string& op = "OpOneOut";
93
94 EXPECT_EQ("Shape inference should have returned error",
95 RunInferShapes(op, "[1];[2];[1]", "e", fn_copy_input_0));
96 EXPECT_CONTAINS(RunInferShapes(op, "[1];[2];[1]", "[1];[2]", fn_copy_input_0),
97 "wrong number of outputs");
98 auto error_message = ShapeInferenceTestutil::InferShapes(
99 ShapeInferenceTestOp("NoSuchOp"), "", "")
100 .error_message();
101 EXPECT_TRUE(
102 absl::StartsWith(error_message, "Op type not registered 'NoSuchOp'"));
103
104 // Wrong shape error messages.
105 EXPECT_CONTAINS(RunInferShapes(op, "[1];[2];[1]", "?", fn_copy_input_0),
106 "expected to not match");
107 EXPECT_CONTAINS(RunInferShapes(op, "[1];[2];[1]", "in2", fn_copy_input_0),
108 "should have matched one of (in2)");
109 EXPECT_CONTAINS(RunInferShapes(op, "[1];[2];[1]", "in1|in2", fn_copy_input_0),
110 "should have matched one of (in1|in2)");
111 EXPECT_CONTAINS(RunInferShapes(op, "[1];[2];[1]", "[1]", fn_copy_input_2),
112 "but was expected to not match");
113 EXPECT_CONTAINS(RunInferShapes(op, "[1];[2];[1]", "in0|in1", fn_output_1_2),
114 "Output 0 should have matched an input shape");
115 EXPECT_EQ("Output 0 expected to be unknown. Output shape was [1,2]",
116 RunInferShapes(op, "[1];[2];[1]", "?", fn_output_1_2));
117 EXPECT_EQ("Output 0 expected rank 3 but was 2. Output shape was [1,2]",
118 RunInferShapes(op, "[1];[2];[1]", "[1,2,3]", fn_output_1_2));
119 EXPECT_EQ(
120 "Output 0 expected rank 2 but was ?. Output shape was ?",
121 RunInferShapes(op, "[1];[2];[1]", "[1,2]", fn_output_unknown_shapes));
122
123 // Wrong shape error messages on the second output.
124 EXPECT_EQ("Output 1 expected rank 3 but was ?. Output shape was ?",
125 RunInferShapes("OpTwoOut", "[1];[2];[1]", "?;[1,2,3]",
126 fn_output_unknown_shapes));

Callers

nothing calls this directly

Calls 13

RunInferShapesFunction · 0.85
InferShapesFunction · 0.85
StartsWithFunction · 0.85
UnknownShapeMethod · 0.80
MatrixMethod · 0.80
UnknownDimMethod · 0.80
set_outputMethod · 0.45
inputMethod · 0.45
num_outputsMethod · 0.45
MakeShapeMethod · 0.45
DimMethod · 0.45

Tested by

no test coverage detected