Benchmark regression
authorAlexandre Passos <apassos@google.com>
Mon, 5 Mar 2018 21:36:30 +0000 (13:36 -0800)
committerTensorFlower Gardener <gardener@tensorflow.org>
Mon, 5 Mar 2018 21:40:40 +0000 (13:40 -0800)
PiperOrigin-RevId: 187914657

tensorflow/python/ops/array_ops.py
tensorflow/python/ops/losses/losses_impl.py

index cc55969..bd1e84e 100644 (file)
@@ -388,10 +388,7 @@ def size_internal(input, name=None, optimize=True, out_type=dtypes.int32):
   if context.in_eager_mode() and not isinstance(
       input, (sparse_tensor.SparseTensor,
               sparse_tensor.SparseTensorValue)):
-    size_ = 1
-    for dim in ops.convert_to_tensor(input)._shape_tuple():  # pylint: disable=protected-access
-      size_ *= dim
-    return size_
+    return np.prod(ops.convert_to_tensor(input)._shape_tuple())  # pylint: disable=protected-access
   with ops.name_scope(name, "Size", [input]) as name:
     if isinstance(input, (sparse_tensor.SparseTensor,
                           sparse_tensor.SparseTensorValue)):
index a394171..0cae3c1 100644 (file)
@@ -89,14 +89,6 @@ def _safe_div(numerator, denominator, name="value"):
   Returns:
     The element-wise value of the numerator divided by the denominator.
   """
-  if isinstance(denominator, float):
-    if math_ops.equal(denominator, 0.0):
-      return ops.convert_to_tensor(0.0, dtype=numerator.dtype)
-    return math_ops.div(numerator, denominator)
-  if context.in_eager_mode() and denominator._rank() == 0:  # pylint: disable=protected-access
-    if math_ops.equal(denominator, 0.0):
-      return ops.convert_to_tensor(0.0, dtype=numerator.dtype)
-    return math_ops.div(numerator, denominator)
   return array_ops.where(
       math_ops.greater(denominator, 0),
       math_ops.div(numerator, array_ops.where(