diff options
Diffstat (limited to 'tensorflow/python/kernel_tests/constant_op_test.py')
-rw-r--r-- | tensorflow/python/kernel_tests/constant_op_test.py | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/tensorflow/python/kernel_tests/constant_op_test.py b/tensorflow/python/kernel_tests/constant_op_test.py index 107ee37fab..d1e4e5477f 100644 --- a/tensorflow/python/kernel_tests/constant_op_test.py +++ b/tensorflow/python/kernel_tests/constant_op_test.py @@ -162,18 +162,18 @@ class ConstantTest(test.TestCase): logging_const_op.run() def testStringWithNulls(self): - with self.test_session(): + with self.cached_session(): val = ops.convert_to_tensor(b"\0\0\0\0").eval() self.assertEqual(len(val), 4) self.assertEqual(val, b"\0\0\0\0") - with self.test_session(): + with self.cached_session(): val = ops.convert_to_tensor(b"xx\0xx").eval() self.assertEqual(len(val), 5) self.assertAllEqual(val, b"xx\0xx") nested = [[b"\0\0\0\0", b"xx\0xx"], [b"\0_\0_\0_\0", b"\0"]] - with self.test_session(): + with self.cached_session(): val = ops.convert_to_tensor(nested).eval() # NOTE(mrry): Do not use assertAllEqual, because it converts nested to a # numpy array, which loses the null terminators. @@ -279,7 +279,7 @@ class AsTensorTest(test.TestCase): self.assertTrue(isinstance(x, ops.Tensor)) def testAsTensorForShapeInput(self): - with self.test_session(): + with self.cached_session(): x = ops.convert_to_tensor(tensor_shape.TensorShape([])) self.assertEqual(dtypes_lib.int32, x.dtype) self.assertAllEqual([], x.eval()) @@ -331,7 +331,7 @@ class AsTensorTest(test.TestCase): tensor_shape.TensorShape([1, 2, 3]), dtype=dtypes_lib.float32) def testAsTensorForDimensionInput(self): - with self.test_session(): + with self.cached_session(): x = ops.convert_to_tensor(tensor_shape.TensorShape([1, 2, 3])[1]) self.assertEqual(dtypes_lib.int32, x.dtype) self.assertAllEqual(2, x.eval()) @@ -367,7 +367,7 @@ class IdentityOpTest(test.TestCase): class ZerosTest(test.TestCase): def _Zeros(self, shape): - with self.test_session(): + with self.cached_session(): ret = array_ops.zeros(shape) self.assertEqual(shape, ret.get_shape()) return ret.eval() @@ -379,13 +379,13 @@ class ZerosTest(test.TestCase): def testScalar(self): self.assertEqual(0, self._Zeros([])) self.assertEqual(0, self._Zeros(())) - with self.test_session(): + with self.cached_session(): scalar = array_ops.zeros(constant_op.constant([], dtype=dtypes_lib.int32)) self.assertEqual(0, scalar.eval()) def testDynamicSizes(self): np_ans = np.array([[0] * 3] * 2) - with self.test_session(): + with self.cached_session(): # Creates a tensor of 2 x 3. d = array_ops.fill([2, 3], 12., name="fill") # Constructs a tensor of zeros of the same dimensions as "d". @@ -396,7 +396,7 @@ class ZerosTest(test.TestCase): self.assertShapeEqual(np_ans, z) def testDtype(self): - with self.test_session(): + with self.cached_session(): d = array_ops.fill([2, 3], 12., name="fill") self.assertEqual(d.get_shape(), [2, 3]) # Test default type for both constant size and dynamic size @@ -489,7 +489,7 @@ class ZerosLikeTest(test.TestCase): def testZerosLikeDtype(self): # Make sure zeros_like works even for dtypes that cannot be cast between - with self.test_session(): + with self.cached_session(): shape = (3, 5) dtypes = np.float32, np.complex64 for in_type in dtypes: @@ -533,7 +533,7 @@ class ZerosLikeTest(test.TestCase): class OnesTest(test.TestCase): def _Ones(self, shape): - with self.test_session(): + with self.cached_session(): ret = array_ops.ones(shape) self.assertEqual(shape, ret.get_shape()) return ret.eval() @@ -544,13 +544,13 @@ class OnesTest(test.TestCase): def testScalar(self): self.assertEqual(1, self._Ones([])) self.assertEqual(1, self._Ones(())) - with self.test_session(): + with self.cached_session(): scalar = array_ops.ones(constant_op.constant([], dtype=dtypes_lib.int32)) self.assertEqual(1, scalar.eval()) def testDynamicSizes(self): np_ans = np.array([[1] * 3] * 2) - with self.test_session(): + with self.cached_session(): # Creates a tensor of 2 x 3. d = array_ops.fill([2, 3], 12., name="fill") # Constructs a tensor of ones of the same dimensions as "d". @@ -561,7 +561,7 @@ class OnesTest(test.TestCase): self.assertShapeEqual(np_ans, z) def testAutoPack(self): - with self.test_session(): + with self.cached_session(): h = array_ops.placeholder(dtypes_lib.int32, shape=[]) w = array_ops.placeholder(dtypes_lib.int32, shape=[]) z = array_ops.ones([h, w]) @@ -569,7 +569,7 @@ class OnesTest(test.TestCase): self.assertAllEqual(out, np.array([[1] * 16] * 4)) def testDtype(self): - with self.test_session(): + with self.cached_session(): d = array_ops.fill([2, 3], 12., name="fill") self.assertEqual(d.get_shape(), [2, 3]) # Test default type for both constant size and dynamic size @@ -606,7 +606,7 @@ class OnesLikeTest(test.TestCase): dtypes_lib.complex128 ]: numpy_dtype = dtype.as_numpy_dtype - with self.test_session(): + with self.cached_session(): # Creates a tensor of non-zero values with shape 2 x 3. d = constant_op.constant( np.ones( @@ -672,7 +672,7 @@ class FillTest(test.TestCase): self.assertAllEqual(np_ans, tf_ans) def testFillNegative(self): - with self.test_session(): + with self.cached_session(): for shape in (-1,), (2, -1), (-1, 2), (-2), (-3): with self.assertRaises(ValueError): array_ops.fill(shape, 7) @@ -703,7 +703,7 @@ class FillTest(test.TestCase): self.assertEqual([None, 17], f.get_shape().as_list()) def testGradient(self): - with self.test_session(): + with self.cached_session(): in_v = constant_op.constant(5.0) out_shape = [3, 2] out_filled = array_ops.fill(out_shape, in_v) @@ -715,7 +715,7 @@ class FillTest(test.TestCase): class PlaceholderTest(test.TestCase): def testDtype(self): - with self.test_session(): + with self.cached_session(): p = array_ops.placeholder(dtypes_lib.float32, shape=(10, 10), name="p") p_identity = array_ops.identity(p) feed_array = np.random.rand(10, 10) @@ -727,7 +727,7 @@ class PlaceholderTest(test.TestCase): p_identity.eval() def testShape(self): - with self.test_session(): + with self.cached_session(): p = array_ops.placeholder(dtypes_lib.float32, shape=(10, 10), name="p") p_identity = array_ops.identity(p) feed_array = np.random.rand(10, 10) @@ -744,7 +744,7 @@ class PlaceholderTest(test.TestCase): p_identity.eval(feed_dict={p: feed_array[:5, :5]}) def testUnknownShape(self): - with self.test_session(): + with self.cached_session(): p = array_ops.placeholder(dtypes_lib.float32, shape=None, name="p") p_identity = array_ops.identity(p) # can feed anything @@ -756,13 +756,13 @@ class PlaceholderTest(test.TestCase): p_identity.eval(feed_dict={p: feed_array}), feed_array) def testScalarShape(self): - with self.test_session(): + with self.cached_session(): p = array_ops.placeholder(dtypes_lib.float32, shape=[], name="p") p_identity = array_ops.identity(p) self.assertAllClose(p_identity.eval(feed_dict={p: 5}), 5) def testPartialShape(self): - with self.test_session(): + with self.cached_session(): p = array_ops.placeholder(dtypes_lib.float32, shape=[None, 3], name="p") p_identity = array_ops.identity(p) feed_array = np.random.rand(10, 3) @@ -774,7 +774,7 @@ class PlaceholderTest(test.TestCase): p_identity.eval(feed_dict={p: feed_array[:5, :2]}) def testPartialShapeWhenNotFed(self): - with self.test_session(): + with self.cached_session(): p = array_ops.placeholder(dtypes_lib.float32, shape=[None, 3], name="p") p_identity = array_ops.identity(p) @@ -784,7 +784,7 @@ class PlaceholderTest(test.TestCase): p_identity.eval() def testControlDependency(self): - with self.test_session(): + with self.cached_session(): p = array_ops.placeholder(dtypes_lib.int32, shape=[], name="p") with ops.control_dependencies([p]): c = constant_op.constant(5, dtypes_lib.int32) @@ -872,7 +872,7 @@ versions { """ gdef = graph_pb2.GraphDef() text_format.Merge(graph, gdef) - with self.test_session(): + with self.cached_session(): p, ret = importer.import_graph_def( gdef, return_elements=["Placeholder:0", "add:0"]) |