aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/python/kernel_tests
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2018-10-03 10:19:55 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-10-03 10:27:27 -0700
commita5b3cd8b4d28cfcdcb9adb3d3568b168b9b8a088 (patch)
tree97c740eebd5de54244fdb8188c1c658c94a93523 /tensorflow/python/kernel_tests
parent022af5300701d457d848e60ea511dd8d05f68738 (diff)
Fix bug in shape function for transpose: If the rank of the input is unknown and the rank derived from the permutation array is 0 or 1, the shape is ambiguous and cannot be determined at graph construction time. In this case, forward the shape of the input.
PiperOrigin-RevId: 215583050
Diffstat (limited to 'tensorflow/python/kernel_tests')
-rw-r--r--tensorflow/python/kernel_tests/BUILD2
-rw-r--r--tensorflow/python/kernel_tests/transpose_op_test.py29
2 files changed, 28 insertions, 3 deletions
diff --git a/tensorflow/python/kernel_tests/BUILD b/tensorflow/python/kernel_tests/BUILD
index 44575fc452..c0e9a3c975 100644
--- a/tensorflow/python/kernel_tests/BUILD
+++ b/tensorflow/python/kernel_tests/BUILD
@@ -2367,7 +2367,7 @@ cuda_py_test(
"//tensorflow/python:client_testlib",
"//tensorflow/python:framework_for_generated_wrappers",
],
- shard_count = 4,
+ shard_count = 10,
tags = [
"no_gpu",
"no_oss",
diff --git a/tensorflow/python/kernel_tests/transpose_op_test.py b/tensorflow/python/kernel_tests/transpose_op_test.py
index f42800226e..a825052dd2 100644
--- a/tensorflow/python/kernel_tests/transpose_op_test.py
+++ b/tensorflow/python/kernel_tests/transpose_op_test.py
@@ -39,7 +39,12 @@ class TransposeTest(test.TestCase):
return ret
def _compareCpu(self, x, p, conjugate=False):
- np_ans = self._np_transpose(x, p)
+ if p is None:
+ rank = x.ndim
+ perm = (rank - 1) - np.arange(rank)
+ else:
+ perm = p
+ np_ans = self._np_transpose(x, perm)
if conjugate:
np_ans = np.conj(np_ans)
with self.test_session(use_gpu=False):
@@ -65,7 +70,12 @@ class TransposeTest(test.TestCase):
return tf_ans, jacob_t
def _compareGpu(self, x, p, conjugate=False):
- np_ans = self._np_transpose(x, p)
+ if p is None:
+ rank = x.ndim
+ perm = (rank - 1) - np.arange(rank)
+ else:
+ perm = p
+ np_ans = self._np_transpose(x, perm)
if conjugate:
np_ans = np.conj(np_ans)
with self.test_session(use_gpu=True):
@@ -102,6 +112,11 @@ class TransposeTest(test.TestCase):
self._compareCpu(x, p, conjugate=c)
if use_gpu:
self._compareGpu(x, p, conjugate=c)
+ # Test with an empty permutation
+ for c in cs:
+ self._compareCpu(x, None, conjugate=c)
+ if use_gpu:
+ self._compareGpu(x, None, conjugate=c)
def _compare_cpu_gpu(self, x):
n = np.ndim(x)
@@ -449,6 +464,10 @@ class TransposeTest(test.TestCase):
self.assertEqual(
tensor_shape.TensorShape(None),
array_ops.transpose(array_ops.placeholder(dtypes.int32)).get_shape())
+ self.assertEqual(
+ tensor_shape.TensorShape(None),
+ array_ops.transpose(array_ops.placeholder(dtypes.int32),
+ [0]).get_shape())
def testNullTensor(self):
with self.cached_session():
@@ -456,6 +475,12 @@ class TransposeTest(test.TestCase):
xt = array_ops.transpose(x, [0, 2, 1]).eval()
self.assertAllEqual(xt.shape, (1, 0, 4))
+ def testScalar(self):
+ with self.cached_session():
+ x = constant_op.constant(42, dtype=dtypes.float32, shape=[])
+ xt = array_ops.transpose(x).eval()
+ self.assertAllEqual(xt, x)
+
def _testError(self, x, p, err):
with self.cached_session():
with self.assertRaisesOpError(err):