aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/python/kernel_tests/sparse_matmul_op_test.py
diff options
context:
space:
mode:
authorGravatar Manjunath Kudlur <keveman@gmail.com>2015-11-25 08:48:47 -0800
committerGravatar Manjunath Kudlur <keveman@gmail.com>2015-11-25 08:48:47 -0800
commit854f49bd43588c062b046384f239f64a3d819702 (patch)
treec2373bf71ef65ae4c116ea703947141281c1eace /tensorflow/python/kernel_tests/sparse_matmul_op_test.py
parent9c3043ff3bf31a6a81810b4ce9e87ef936f1f529 (diff)
TensorFlow: Upstream changes to git
Changes: - Updates to docs - Several changes for Python 3 compatibility - Added license headers Base CL: 108710566
Diffstat (limited to 'tensorflow/python/kernel_tests/sparse_matmul_op_test.py')
-rw-r--r--tensorflow/python/kernel_tests/sparse_matmul_op_test.py33
1 files changed, 23 insertions, 10 deletions
diff --git a/tensorflow/python/kernel_tests/sparse_matmul_op_test.py b/tensorflow/python/kernel_tests/sparse_matmul_op_test.py
index 3e5e059327..8f0c60c455 100644
--- a/tensorflow/python/kernel_tests/sparse_matmul_op_test.py
+++ b/tensorflow/python/kernel_tests/sparse_matmul_op_test.py
@@ -46,11 +46,11 @@ class SparseMatMulTest(tf.test.TestCase):
np_ans = x_mat * y_mat
with self.test_session(use_gpu=False):
tf_ans = tf.matmul(x, y,
- transpose_a=tr_a, transpose_b=tr_b,
- a_is_sparse=sp_a,
- b_is_sparse=sp_b)
+ transpose_a=tr_a, transpose_b=tr_b,
+ a_is_sparse=sp_a,
+ b_is_sparse=sp_b)
out = tf_ans.eval()
- self.assertAllClose(np_ans, out)
+ self.assertAllClose(np_ans, out, rtol=1e-4, atol=1e-4)
self.assertShapeEqual(np_ans, tf_ans)
def testFloatBasic(self):
@@ -58,7 +58,20 @@ class SparseMatMulTest(tf.test.TestCase):
y = np.arange(-1., 1.).reshape([1, 2]).astype(np.float32)
self._testCpuMatmul(x, y)
- # Tests testing random sized matrices.
+ # Tests setting one dimension to be a high value.
+ def testFloatLarge(self):
+ r1 = np.random.randint(6000, 20000)
+ r2 = np.random.randint(1, 10)
+ r3 = np.random.randint(1, 10)
+ for m, k, n in [(r1, r2, r3),
+ (r2, r1, r3),
+ (r2, r3, r1)]:
+ x = RandMatrix(m, k, False)
+ y = RandMatrix(k, n, False)
+ self._testCpuMatmul(x, y)
+ self._testCpuMatmul(x, y, sp_a=False, sp_b=True)
+
+ # Tests random sized matrices.
def testFloatRandom(self):
for _ in range(10):
for tr_a in [True, False]:
@@ -78,11 +91,11 @@ class MatMulGradientTest(tf.test.TestCase):
a = tf.constant(RandMatrix(3, 2, tr_a), dtype=tf.float32)
b = tf.constant(RandMatrix(2, 4, tr_b), dtype=tf.float32)
m = tf.matmul(a, b,
- name=name,
- transpose_a=tr_a,
- transpose_b=tr_b,
- a_is_sparse=sp_a,
- b_is_sparse=sp_b)
+ name=name,
+ transpose_a=tr_a,
+ transpose_b=tr_b,
+ a_is_sparse=sp_a,
+ b_is_sparse=sp_b)
err = (gc.ComputeGradientError(a, [2, 3] if tr_a else [3, 2], m, [3, 4]) +
gc.ComputeGradientError(b, [4, 2] if tr_b else [2, 4], m, [3, 4]))
print("sparse_matmul gradient err = ", err)