From 5da4df92c2d27132077d9316ce40421b0656a241 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Tue, 12 Sep 2017 11:35:31 -0700 Subject: [PATCH] Simplify some code in grappler_item_builder.cc, no change in logic. PiperOrigin-RevId: 168409110 --- .../core/grappler/grappler_item_builder.cc | 32 +++++++------------ 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/tensorflow/core/grappler/grappler_item_builder.cc b/tensorflow/core/grappler/grappler_item_builder.cc index 33081061c01..cb7d7f7330c 100644 --- a/tensorflow/core/grappler/grappler_item_builder.cc +++ b/tensorflow/core/grappler/grappler_item_builder.cc @@ -315,27 +315,17 @@ std::unique_ptr GrapplerItemFromMetaGraphDef( // We only do this if cfg.placeholder_unknown_output_shape_dim has // been set to avoid crashing non-BNMT graphs. if ((cfg.placeholder_unknown_output_shape_dim >= 0) && - (shape.dims() == 0) && (node.attr().count("_output_shapes") == 1) && - (node.attr().at("_output_shapes").list().shape(0).dim_size() != 0)) { - shape.Clear(); - shape_proto.clear_dim(); - for (int dim_i = 0; - dim_i < - node.attr().at("_output_shapes").list().shape(0).dim_size(); - dim_i++) { - const ::tensorflow::TensorShapeProto_Dim dim = - node.attr().at("_output_shapes").list().shape(0).dim(dim_i); - if (dim.size() == -1) { - shape.AddDim(cfg.placeholder_unknown_output_shape_dim); - shape_proto.add_dim()->set_size( - cfg.placeholder_unknown_output_shape_dim); - } else { - int size = node.attr() - .at("_output_shapes") - .list() - .shape(0) - .dim(dim_i) - .size(); + (shape.dims() == 0) && (node.attr().count("_output_shapes") == 1)) { + const auto& output_shapes = + node.attr().at("_output_shapes").list().shape(0); + + if (output_shapes.dim_size() != 0) { + shape.Clear(); + shape_proto.clear_dim(); + + for (const auto& dim : output_shapes.dim()) { + auto size = dim.size(); + if (size == -1) size = cfg.placeholder_unknown_output_shape_dim; shape.AddDim(size); shape_proto.add_dim()->set_size(size); }