From a9261f12430bf772c2245fa8aa930f429b890294 Mon Sep 17 00:00:00 2001 From: Ben Barsdell Date: Wed, 24 Apr 2019 10:46:47 -0700 Subject: [PATCH] Use TensorShape::num_elements() instead of loop --- .../core/grappler/optimizers/constant_folding.cc | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/tensorflow/core/grappler/optimizers/constant_folding.cc b/tensorflow/core/grappler/optimizers/constant_folding.cc index 2016c80743f..bc3c6f244f4 100644 --- a/tensorflow/core/grappler/optimizers/constant_folding.cc +++ b/tensorflow/core/grappler/optimizers/constant_folding.cc @@ -2394,15 +2394,9 @@ bool ConstantFolding::IsReductionWithConstantIndices( !reductions_indices->attr().count("value")) { return false; } - const TensorProto& reduction_indices_tensor = - reductions_indices->attr().at("value").tensor(); - *indices_is_empty = false; - for (const auto& dim : reduction_indices_tensor.tensor_shape().dim()) { - if (dim.size() == 0) { - *indices_is_empty = true; - break; - } - } + const TensorShapeProto& reduction_indices_shape = + reductions_indices->attr().at("value").tensor().tensor_shape(); + *indices_is_empty = TensorShape(reduction_indices_shape).num_elements() == 0; return true; }