| 70 | }; |
| 71 | |
| 72 | TEST_F(ShapeInferenceTest, InputOutputByName) { |
| 73 | // Setup test to contain an input tensor list of size 3. |
| 74 | OpDef op_def = MakeOpDefWithLists(); |
| 75 | NodeDef def; |
| 76 | auto s = NodeDefBuilder("dummy", &op_def) |
| 77 | .Attr("N", 3) |
| 78 | .Input(FakeInput(DT_FLOAT)) |
| 79 | .Finalize(&def); |
| 80 | InferenceContext c(kVersion, &def, op_def, {S({1, 5}), S({2, 5}), S({1, 3})}, |
| 81 | {}, {}, {}); |
| 82 | |
| 83 | EXPECT_EQ("5", c.DebugString(c.NumElements(c.input(0)))); |
| 84 | EXPECT_EQ("10", c.DebugString(c.NumElements(c.input(1)))); |
| 85 | EXPECT_EQ("3", c.DebugString(c.NumElements(c.input(2)))); |
| 86 | // Test getters. |
| 87 | std::vector<ShapeHandle> shapes; |
| 88 | EXPECT_FALSE(c.input("nonexistent", &shapes).ok()); |
| 89 | TF_EXPECT_OK(c.input("input", &shapes)); |
| 90 | EXPECT_EQ("[1,5]", c.DebugString(shapes[0])); |
| 91 | EXPECT_EQ("[2,5]", c.DebugString(shapes[1])); |
| 92 | EXPECT_EQ("[1,3]", c.DebugString(shapes[2])); |
| 93 | |
| 94 | // Test setters. |
| 95 | EXPECT_FALSE(c.set_output("nonexistent", shapes).ok()); |
| 96 | TF_EXPECT_OK(c.set_output("output", shapes)); |
| 97 | EXPECT_EQ("5", c.DebugString(c.NumElements(c.output(0)))); |
| 98 | EXPECT_EQ("10", c.DebugString(c.NumElements(c.output(1)))); |
| 99 | EXPECT_EQ("3", c.DebugString(c.NumElements(c.output(2)))); |
| 100 | } |
| 101 | |
| 102 | static OpDef MakeOpDef(int num_inputs, int num_outputs) { |
| 103 | OpRegistrationData op_reg_data; |
nothing calls this directly
no test coverage detected