aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/python/kernel_tests/reverse_sequence_op_test.py
diff options
context:
space:
mode:
authorGravatar Andrew Selle <aselle@google.com>2016-11-30 17:39:34 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-11-30 17:46:25 -0800
commit83cef3f1f4ce4177c5bcf38b6a24e920dc12fba7 (patch)
tree4f2393661e06489b762faedf516dde0b9ac14a87 /tensorflow/python/kernel_tests/reverse_sequence_op_test.py
parent25e3ed65a66f4fb521db940f3038328178aa82d7 (diff)
Rename more argument names to be consistent with NumPy.
Create temporary dummy arguments with old names at the end in preparation for deprecation. Change: 140675930
Diffstat (limited to 'tensorflow/python/kernel_tests/reverse_sequence_op_test.py')
-rw-r--r--tensorflow/python/kernel_tests/reverse_sequence_op_test.py96
1 files changed, 57 insertions, 39 deletions
diff --git a/tensorflow/python/kernel_tests/reverse_sequence_op_test.py b/tensorflow/python/kernel_tests/reverse_sequence_op_test.py
index fbfad8327e..ca6b198fa8 100644
--- a/tensorflow/python/kernel_tests/reverse_sequence_op_test.py
+++ b/tensorflow/python/kernel_tests/reverse_sequence_op_test.py
@@ -25,13 +25,17 @@ import tensorflow as tf
class ReverseSequenceTest(tf.test.TestCase):
- def _testReverseSequence(self, x, batch_dim, seq_dim, seq_lengths,
- truth, use_gpu=False, expected_err_re=None):
+ def _testReverseSequence(self,
+ x,
+ batch_axis,
+ seq_axis,
+ seq_lengths,
+ truth,
+ use_gpu=False,
+ expected_err_re=None):
with self.test_session(use_gpu=use_gpu):
- ans = tf.reverse_sequence(x,
- batch_dim=batch_dim,
- seq_dim=seq_dim,
- seq_lengths=seq_lengths)
+ ans = tf.reverse_sequence(
+ x, batch_axis=batch_axis, seq_axis=seq_axis, seq_lengths=seq_lengths)
if expected_err_re is None:
tf_ans = ans.eval()
self.assertAllClose(tf_ans, truth, atol=1e-10)
@@ -40,12 +44,17 @@ class ReverseSequenceTest(tf.test.TestCase):
with self.assertRaisesOpError(expected_err_re):
ans.eval()
- def _testBothReverseSequence(self, x, batch_dim, seq_dim, seq_lengths,
- truth, expected_err_re=None):
- self._testReverseSequence(x, batch_dim, seq_dim, seq_lengths,
- truth, True, expected_err_re)
- self._testReverseSequence(x, batch_dim, seq_dim, seq_lengths,
- truth, False, expected_err_re)
+ def _testBothReverseSequence(self,
+ x,
+ batch_axis,
+ seq_axis,
+ seq_lengths,
+ truth,
+ expected_err_re=None):
+ self._testReverseSequence(x, batch_axis, seq_axis, seq_lengths, truth, True,
+ expected_err_re)
+ self._testReverseSequence(x, batch_axis, seq_axis, seq_lengths, truth,
+ False, expected_err_re)
def _testBasic(self, dtype, len_dtype=np.int64):
x = np.asarray([
@@ -66,9 +75,9 @@ class ReverseSequenceTest(tf.test.TestCase):
truth_orig = truth_orig.reshape(3, 2, 4, 1, 1)
truth = truth_orig.transpose([2, 1, 0, 3, 4]) # permute axes 0 <=> 2
- seq_dim = 0 # permute seq_dim and batch_dim (originally 2 and 0, resp.)
- batch_dim = 2
- self._testBothReverseSequence(x, batch_dim, seq_dim, seq_lengths, truth)
+ seq_axis = 0 # permute seq_axis and batch_axis (originally 2 and 0, resp.)
+ batch_axis = 2
+ self._testBothReverseSequence(x, batch_axis, seq_axis, seq_lengths, truth)
def testSeqLengthInt32(self):
self._testBasic(np.float32, np.int32)
@@ -100,17 +109,18 @@ class ReverseSequenceTest(tf.test.TestCase):
x = x.transpose([2, 1, 0, 3, 4]) # transpose axes 0 <=> 2
# reverse dim 0 up to (0:3, none, 0:4) along dim=2
- seq_dim = 0
- batch_dim = 2
+ seq_axis = 0
+ batch_axis = 2
seq_lengths = np.asarray([3, 0, 4], dtype=np.int64)
with self.test_session():
input_t = tf.constant(x, shape=x.shape)
seq_lengths_t = tf.constant(seq_lengths, shape=seq_lengths.shape)
- reverse_sequence_out = tf.reverse_sequence(input_t,
- batch_dim=batch_dim,
- seq_dim=seq_dim,
- seq_lengths=seq_lengths_t)
+ reverse_sequence_out = tf.reverse_sequence(
+ input_t,
+ batch_axis=batch_axis,
+ seq_axis=seq_axis,
+ seq_lengths=seq_lengths_t)
err = tf.test.compute_gradient_error(input_t,
x.shape,
reverse_sequence_out,
@@ -121,41 +131,49 @@ class ReverseSequenceTest(tf.test.TestCase):
def testShapeFunctionEdgeCases(self):
t = tf.reverse_sequence(
- tf.placeholder(tf.float32, shape=None),
- seq_lengths=tf.placeholder(tf.int64, shape=(32,)),
- batch_dim=0, seq_dim=1)
+ tf.placeholder(
+ tf.float32, shape=None),
+ seq_lengths=tf.placeholder(
+ tf.int64, shape=(32,)),
+ batch_axis=0,
+ seq_axis=1)
self.assertIs(t.get_shape().ndims, None)
# Batch size mismatched between input and seq_lengths.
with self.assertRaises(ValueError):
tf.reverse_sequence(
- tf.placeholder(tf.float32, shape=(32, 2, 3)),
- seq_lengths=tf.placeholder(tf.int64, shape=(33,)),
- seq_dim=3)
+ tf.placeholder(
+ tf.float32, shape=(32, 2, 3)),
+ seq_lengths=tf.placeholder(
+ tf.int64, shape=(33,)),
+ seq_axis=3)
- # seq_dim out of bounds.
+ # seq_axis out of bounds.
with self.assertRaisesRegexp(ValueError, "seq_dim must be < input rank"):
tf.reverse_sequence(
- tf.placeholder(tf.float32, shape=(32, 2, 3)),
- seq_lengths=tf.placeholder(tf.int64, shape=(32,)),
- seq_dim=3)
+ tf.placeholder(
+ tf.float32, shape=(32, 2, 3)),
+ seq_lengths=tf.placeholder(
+ tf.int64, shape=(32,)),
+ seq_axis=3)
- # batch_dim out of bounds.
+ # batch_axis out of bounds.
with self.assertRaisesRegexp(
ValueError, "batch_dim must be < input rank"):
tf.reverse_sequence(
- tf.placeholder(tf.float32, shape=(32, 2, 3)),
- seq_lengths=tf.placeholder(tf.int64, shape=(32,)),
- seq_dim=0,
- batch_dim=3)
+ tf.placeholder(
+ tf.float32, shape=(32, 2, 3)),
+ seq_lengths=tf.placeholder(
+ tf.int64, shape=(32,)),
+ seq_axis=0,
+ batch_axis=3)
with self.test_session():
inputs = tf.placeholder(tf.float32, shape=(32, 2, 3))
seq_lengths = tf.placeholder(tf.int64, shape=(32,))
output = tf.reverse_sequence(
- inputs,
- seq_lengths=seq_lengths,
- seq_dim=0) # batch_dim default is 0
+ inputs, seq_lengths=seq_lengths,
+ seq_axis=0) # batch_axis default is 0
with self.assertRaisesOpError("batch_dim == seq_dim"):
output.eval(feed_dict={inputs: np.random.rand(32, 2, 3),
seq_lengths: xrange(32)})