Merge pull request #39481 from yongtang:39475-tf.divide-tensor

PiperOrigin-RevId: 311405733
Change-Id: If25000df313267fffb594a66291a208ce2a64ed0
This commit is contained in:
TensorFlower Gardener 2020-05-13 14:36:44 -07:00
commit eb7af8c54d
2 changed files with 10 additions and 0 deletions

View File

@ -82,6 +82,7 @@ from tensorflow.python.framework import graph_util
from tensorflow.python.framework import ops from tensorflow.python.framework import ops
from tensorflow.python.framework import sparse_tensor from tensorflow.python.framework import sparse_tensor
from tensorflow.python.framework import tensor_shape from tensorflow.python.framework import tensor_shape
from tensorflow.python.framework import tensor_util
from tensorflow.python.ops import array_ops from tensorflow.python.ops import array_ops
from tensorflow.python.ops import gen_array_ops from tensorflow.python.ops import gen_array_ops
from tensorflow.python.ops import gen_data_flow_ops from tensorflow.python.ops import gen_data_flow_ops
@ -438,6 +439,9 @@ def divide(x, y, name=None):
# override names. Use a dummy class to track the runtime division behavior # override names. Use a dummy class to track the runtime division behavior
return DivideDelegateWithName(x, name) / y return DivideDelegateWithName(x, name) / y
else: else:
# We do conversion here to make sure at least x is a tensor.
if not tensor_util.is_tensor(x):
x = ops.convert_to_tensor(x)
return x / y return x / y

View File

@ -495,6 +495,12 @@ class DivAndModTest(test_util.TensorFlowTestCase):
# Consistent with desire to get numerator # Consistent with desire to get numerator
self.assertAllEqual(tf_result, expanded_nums) self.assertAllEqual(tf_result, expanded_nums)
def testWithPythonValue(self):
# Test case for GitHub issue 39475:
# https://github.com/tensorflow/tensorflow/issues/39475
x = math_ops.divide(5, 2)
self.assertTrue(isinstance(x, ops.Tensor))
@test_util.run_all_in_graph_and_eager_modes @test_util.run_all_in_graph_and_eager_modes
class DivNoNanTest(test_util.TensorFlowTestCase): class DivNoNanTest(test_util.TensorFlowTestCase):