From a7cd4dbea9f276160ebadf82178e77ae5c8d557e Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Sat, 1 Dec 2018 21:02:04 +0000 Subject: [PATCH] Add test case for sparse_dense_cwise shape validation. Signed-off-by: Yong Tang --- tensorflow/python/kernel_tests/sparse_ops_test.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tensorflow/python/kernel_tests/sparse_ops_test.py b/tensorflow/python/kernel_tests/sparse_ops_test.py index 75f65e62517..f58832a89e3 100644 --- a/tensorflow/python/kernel_tests/sparse_ops_test.py +++ b/tensorflow/python/kernel_tests/sparse_ops_test.py @@ -22,6 +22,7 @@ import numpy as np from tensorflow.python.framework import constant_op from tensorflow.python.framework import dtypes +from tensorflow.python.framework import errors from tensorflow.python.framework import ops from tensorflow.python.framework import sparse_tensor from tensorflow.python.framework import test_util @@ -798,6 +799,17 @@ class SparseMathOpsTest(test_util.TensorFlowTestCase): result_tensor.values).eval() self.assertAllEqual(result_np, res_densified) + @test_util.run_deprecated_v1 + def testCwiseShapeValidation(self): + # Test case for GitHub 24072. + with self.session(use_gpu=False): + a = array_ops.ones([3, 4, 1], dtype=dtypes.int32) + b = sparse_tensor.SparseTensor([[0, 0, 1, 0], [0, 0, 3, 0]], [10, 20], [1, 1, 4, 2]) + c = a * b + with self.assertRaisesRegexp(errors.InvalidArgumentError, + "broadcasts dense to sparse only; got incompatible shapes"): + c.eval() + @test_util.run_deprecated_v1 def testCwiseDivAndMul(self): np.random.seed(1618)