Add test case for empty tensor with clip ops.
authorYong Tang <yong.tang.github@outlook.com>
Fri, 18 May 2018 17:29:26 +0000 (17:29 +0000)
committerYong Tang <yong.tang.github@outlook.com>
Fri, 18 May 2018 18:00:28 +0000 (18:00 +0000)
This fix is based on 19337 and 19338. The issue was that
previously an empty tensor for tf.clip_by_value on GPU
triggers a crash. The issue should have been fixed by 19338 and
the recent master. It makes sense to adds the test case for this issue.

This fix adds the test case.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
tensorflow/python/kernel_tests/clip_ops_test.py

index e08123b0417912c479476d8147d832d1715b8882..403836edbbee4089be8d08185957e08ca7c56e2d 100644 (file)
@@ -18,9 +18,12 @@ from __future__ import absolute_import
 from __future__ import division
 from __future__ import print_function
 
+import numpy as np
+
 from tensorflow.python.framework import constant_op
 from tensorflow.python.framework import dtypes
 from tensorflow.python.framework import ops
+from tensorflow.python.ops import array_ops
 from tensorflow.python.ops import clip_ops
 from tensorflow.python.ops import gradient_checker
 from tensorflow.python.platform import test
@@ -414,6 +417,13 @@ class ClipTest(test.TestCase):
 
     self.assertAllClose(np_ans, tf_ans)
 
+  def testClipByValueEmptyTensor(self):
+    # Test case for GitHub issue 19337
+    z = array_ops.placeholder(dtype=dtypes.float32, shape=None)
+    x = clip_ops.clip_by_value(z, z, 1)
+    with self.test_session(use_gpu=True) as sess:
+      sess.run(x, feed_dict={z: np.zeros((7, 0))})
+
 
 if __name__ == '__main__':
   test.main()