1 /* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15
16 #include "tensorflow/compiler/jit/test_util.h"
17
18 #include "tensorflow/compiler/jit/shape_inference.h"
19 #include "tensorflow/compiler/xla/status_macros.h"
20
21 namespace tensorflow {
22
ShapeAnnotationsMatch(const Graph & graph,const GraphShapeInfo & shape_info,std::map<string,std::vector<PartialTensorShape>> expected_shapes)23 Status ShapeAnnotationsMatch(
24 const Graph& graph, const GraphShapeInfo& shape_info,
25 std::map<string, std::vector<PartialTensorShape>> expected_shapes) {
26 for (Node* node : graph.op_nodes()) {
27 auto sit = shape_info.find(node->name());
28 TF_RET_CHECK(sit != shape_info.end())
29 << "Missing shape information for node " << node->name();
30 std::vector<PartialTensorShape> shapes;
31 for (const auto& output : sit->second) shapes.push_back(output.shape);
32
33 auto it = expected_shapes.find(node->name());
34 if (it != expected_shapes.end()) {
35 if (!PartialTensorShapeUtils::AreIdentical(shapes, it->second)) {
36 return errors::InvalidArgument(
37 "Shape mismatch for ", node->name(), ". Expected: ",
38 PartialTensorShapeUtils::PartialShapeListString(it->second),
39 ", actual: ",
40 PartialTensorShapeUtils::PartialShapeListString(shapes));
41 }
42 expected_shapes.erase(it);
43 }
44 }
45 if (!expected_shapes.empty()) {
46 std::vector<string> missing;
47 missing.reserve(expected_shapes.size());
48 for (const auto& entry : expected_shapes) {
49 missing.push_back(entry.first);
50 }
51 return errors::InvalidArgument("Missing shapes for nodes: ",
52 str_util::Join(missing, ","));
53 }
54 return Status::OK();
55 }
56
57 } // namespace tensorflow
58