diff options
author | 2015-12-11 10:33:31 -0800 | |
---|---|---|
committer | 2015-12-11 10:33:31 -0800 | |
commit | bc624aa8d9460dca794fde6d5534f1d3e8054016 (patch) | |
tree | 6314c95c0583fa32124c6f83baf34a09fe92e31c /tensorflow/python/framework/tensor_util_test.py | |
parent | d9cfc64a2ddf05c0b093c8fb6704c67452ee3ea0 (diff) |
TensorFlow: merge changes from internal
Change 110004767
Add Cast to list of supported ConstantValue ops, mainly useful for shape inference
Change 110002200
Bug fix for b/24814668. The fix uses mdevin's CL/109324239, which adds support to clear control dependency and control flow contexts.
Bug fix for b/25914830. We now clear the control related contexts for initial values of variables in adagrad.
Change 110000213
Further (minor) improvements to print usage in docs and tutorials
Change 109975099
Update `tensor_util.ConstantValue()` to return scalars when appropriate.
The `ConstantValue()` implementations for `tf.size()` and `tf.rank()`
were returning single-element numpy vectors, whereas the op
implementations produce scalar outputs.
Change 109950165
TensorBoard tag to 5
Base CL: 110006867
Diffstat (limited to 'tensorflow/python/framework/tensor_util_test.py')
-rw-r--r-- | tensorflow/python/framework/tensor_util_test.py | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/tensorflow/python/framework/tensor_util_test.py b/tensorflow/python/framework/tensor_util_test.py index f2828475ae..0e2847faf9 100644 --- a/tensorflow/python/framework/tensor_util_test.py +++ b/tensorflow/python/framework/tensor_util_test.py @@ -27,6 +27,7 @@ from tensorflow.python.framework import tensor_util from tensorflow.python.framework import test_util from tensorflow.python.ops import array_ops from tensorflow.python.ops import constant_op +from tensorflow.python.ops import math_ops from tensorflow.python.ops import state_ops from tensorflow.python.platform import googletest @@ -385,19 +386,31 @@ class ConstantValueTest(test_util.TensorFlowTestCase): self.assertEqual(np.int32, c_val.dtype) def testSize(self): - np_val = np.array([6], dtype=np.int32) tf_val = array_ops.size(constant_op.constant(0.0, shape=[1, 2, 3])) c_val = tensor_util.ConstantValue(tf_val) - self.assertAllEqual(np_val, c_val) - self.assertEqual(np.int32, c_val.dtype) + self.assertEqual(6, c_val) + + def testSizeOfScalar(self): + tf_val = array_ops.size(constant_op.constant(0.0)) + c_val = tensor_util.ConstantValue(tf_val) + self.assertEqual(1, c_val) + self.assertEqual(np.int32, type(c_val)) def testRank(self): - np_val = np.array([3], dtype=np.int32) tf_val = array_ops.rank(constant_op.constant(0.0, shape=[1, 2, 3])) c_val = tensor_util.ConstantValue(tf_val) - self.assertAllEqual(np_val, c_val) - self.assertEqual(np.int32, c_val.dtype) + self.assertEqual(3, c_val) + def testCast(self): + np_val = np.random.rand(3, 4, 7).astype(np.float32) + tf_val = math_ops.cast(constant_op.constant(np_val), dtypes.float64) + c_val = tensor_util.ConstantValue(tf_val) + self.assertAllClose(np_val.astype(np.float64), c_val) + + np_val = np.random.rand(3, 0, 7).astype(np.float32) + tf_val = math_ops.cast(constant_op.constant(np_val), dtypes.float64) + c_val = tensor_util.ConstantValue(tf_val) + self.assertAllClose(np_val.astype(np.float64), c_val) if __name__ == "__main__": googletest.main() |