diff options
Diffstat (limited to 'tensorflow/python/kernel_tests/array_ops_test.py')
-rw-r--r-- | tensorflow/python/kernel_tests/array_ops_test.py | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/tensorflow/python/kernel_tests/array_ops_test.py b/tensorflow/python/kernel_tests/array_ops_test.py index a164682227..573bb8614f 100644 --- a/tensorflow/python/kernel_tests/array_ops_test.py +++ b/tensorflow/python/kernel_tests/array_ops_test.py @@ -50,7 +50,7 @@ class BatchMatrixTransposeTest(test_util.TensorFlowTestCase): def testNonBatchMatrix(self): matrix = [[1, 2, 3], [4, 5, 6]] # Shape (2, 3) expected_transposed = [[1, 4], [2, 5], [3, 6]] # Shape (3, 2) - with self.test_session(): + with self.cached_session(): transposed = array_ops.matrix_transpose(matrix) self.assertEqual((3, 2), transposed.get_shape()) self.assertAllEqual(expected_transposed, transposed.eval()) @@ -58,7 +58,7 @@ class BatchMatrixTransposeTest(test_util.TensorFlowTestCase): def testConjugate(self): m = [[1 + 1j, 2 + 2j, 3 + 3j], [4 + 4j, 5 + 5j, 6 + 6j]] expected_transposed = [[1 - 1j, 4 - 4j], [2 - 2j, 5 - 5j], [3 - 3j, 6 - 6j]] - with self.test_session(): + with self.cached_session(): matrix = ops.convert_to_tensor(m) transposed = array_ops.matrix_transpose(matrix, conjugate=True) self.assertEqual((3, 2), transposed.get_shape()) @@ -71,7 +71,7 @@ class BatchMatrixTransposeTest(test_util.TensorFlowTestCase): matrix_1_t = [[11, 44], [22, 55], [33, 66]] batch_matrix = [matrix_0, matrix_1] # Shape (2, 2, 3) expected_transposed = [matrix_0_t, matrix_1_t] # Shape (2, 3, 2) - with self.test_session(): + with self.cached_session(): transposed = array_ops.matrix_transpose(batch_matrix) self.assertEqual((2, 3, 2), transposed.get_shape()) self.assertAllEqual(expected_transposed, transposed.eval()) @@ -79,7 +79,7 @@ class BatchMatrixTransposeTest(test_util.TensorFlowTestCase): def testNonBatchMatrixDynamicallyDefined(self): matrix = [[1, 2, 3], [4, 5, 6]] # Shape (2, 3) expected_transposed = [[1, 4], [2, 5], [3, 6]] # Shape (3, 2) - with self.test_session(): + with self.cached_session(): matrix_ph = array_ops.placeholder(dtypes.int32) transposed = array_ops.matrix_transpose(matrix_ph) self.assertAllEqual( @@ -94,7 +94,7 @@ class BatchMatrixTransposeTest(test_util.TensorFlowTestCase): matrix_1_t = [[11, 44], [22, 55], [33, 66]] batch_matrix = [matrix_0, matrix_1] # Shape (2, 2, 3) expected_transposed = [matrix_0_t, matrix_1_t] # Shape (2, 3, 2) - with self.test_session(): + with self.cached_session(): batch_matrix_ph = array_ops.placeholder(dtypes.int32) transposed = array_ops.matrix_transpose(batch_matrix_ph) self.assertAllEqual( @@ -105,7 +105,7 @@ class BatchMatrixTransposeTest(test_util.TensorFlowTestCase): def testTensorWithStaticRankLessThanTwoRaisesBecauseNotAMatrix(self): vector = [1, 2, 3] - with self.test_session(): + with self.cached_session(): with self.assertRaisesRegexp(ValueError, "should be a "): array_ops.matrix_transpose(vector) @@ -129,7 +129,7 @@ class BooleanMaskTest(test_util.TensorFlowTestCase): masked_arr = arr[:, mask] elif axis == 2: masked_arr = arr[:, :, mask] - with self.test_session(): + with self.cached_session(): masked_tensor = array_ops.boolean_mask(arr, mask, axis=axis) # Leading dimension size of masked_tensor is always unknown until runtime @@ -176,7 +176,7 @@ class BooleanMaskTest(test_util.TensorFlowTestCase): numpy_result = arr[mask] tf_result = array_ops.boolean_mask(arr, mask) self.assertAllEqual(numpy_result.shape[1:], tf_result.get_shape()[1:]) - with self.test_session(): + with self.cached_session(): self.assertAllClose(numpy_result, tf_result.eval()) def testEmptyInput1D(self): @@ -185,7 +185,7 @@ class BooleanMaskTest(test_util.TensorFlowTestCase): numpy_result = arr[mask] tf_result = array_ops.boolean_mask(arr, mask) self.assertAllEqual(numpy_result.shape[1:], tf_result.get_shape()[1:]) - with self.test_session(): + with self.cached_session(): self.assertAllClose(numpy_result, tf_result.eval()) def testEmptyOutput(self): @@ -199,7 +199,7 @@ class BooleanMaskTest(test_util.TensorFlowTestCase): def testWorksWithDimensionsEqualToNoneDuringGraphBuild(self): # The rank of the mask tensor must be specified. This is explained # in the docstring as well. - with self.test_session() as sess: + with self.cached_session() as sess: ph_tensor = array_ops.placeholder(dtypes.int32, shape=None) ph_mask = array_ops.placeholder(dtypes.bool, shape=[None]) @@ -217,7 +217,7 @@ class BooleanMaskTest(test_util.TensorFlowTestCase): def testMaskDimensionsSetToNoneRaises(self): # The rank of the mask tensor must be specified. This is explained # in the docstring as well. - with self.test_session(): + with self.cached_session(): tensor = array_ops.placeholder(dtypes.int32, shape=[None, 2]) mask = array_ops.placeholder(dtypes.bool, shape=None) with self.assertRaisesRegexp(ValueError, "dimensions must be specified"): @@ -226,21 +226,21 @@ class BooleanMaskTest(test_util.TensorFlowTestCase): def testMaskHasMoreDimsThanTensorRaises(self): mask = [[True, True], [False, False]] tensor = [1, 2, 3, 4] - with self.test_session(): + with self.cached_session(): with self.assertRaisesRegexp(ValueError, "incompatible"): array_ops.boolean_mask(tensor, mask).eval() def testMaskIsScalarRaises(self): mask = True tensor = 1 - with self.test_session(): + with self.cached_session(): with self.assertRaisesRegexp(ValueError, "mask.*scalar"): array_ops.boolean_mask(tensor, mask).eval() def testMaskShapeDifferentThanFirstPartOfTensorShapeRaises(self): mask = [True, True, True] tensor = [[1, 2], [3, 4]] - with self.test_session(): + with self.cached_session(): with self.assertRaisesRegexp(ValueError, "incompatible"): array_ops.boolean_mask(tensor, mask).eval() @@ -345,7 +345,7 @@ class ReverseV2Test(test_util.TensorFlowTestCase): def testInvalid(self): x_np = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.float32) axis = array_ops.placeholder(dtypes.int32) - with self.test_session(): + with self.cached_session(): with self.assertRaisesRegexp(errors_impl.InvalidArgumentError, "is out of valid range"): array_ops.reverse_v2(x_np, axis).eval(feed_dict={axis: [-30]}) @@ -954,7 +954,7 @@ class StridedSliceAssignChecker(object): class SliceAssignTest(test_util.TensorFlowTestCase): def testInvalidSlice(self): - with self.test_session() as sess: + with self.cached_session() as sess: foo = constant_op.constant([1, 2, 3]) with self.assertRaisesRegexp(ValueError, "Sliced assignment" " is only supported for variables"): @@ -1000,7 +1000,7 @@ class SliceAssignTest(test_util.TensorFlowTestCase): with self.assertRaisesRegexp( errors.FailedPreconditionError, "Attempting to use uninitialized value Variable"): - with self.test_session() as sess: + with self.cached_session() as sess: v = variables.Variable([1, 2]) sess.run(v[:].assign([1, 2])) @@ -1019,7 +1019,7 @@ class SliceAssignTest(test_util.TensorFlowTestCase): too_small_val = constant_op.constant([3, 4], dtype=dtypes.int8) too_large_val = constant_op.constant([3, 4], dtype=dtypes.int64) v = resource_variable_ops.ResourceVariable(init_val) - with self.test_session() as sess: + with self.cached_session() as sess: sess.run(v.initializer) with self.assertRaises(ValueError): sess.run(v[:].assign(too_large_val)) @@ -1066,12 +1066,12 @@ class ShapeSizeRankTest(test_util.TensorFlowTestCase): class SequenceMaskTest(test_util.TensorFlowTestCase): def testExceptions(self): - with self.test_session(): + with self.cached_session(): with self.assertRaisesRegexp(ValueError, "maxlen must be scalar"): array_ops.sequence_mask([10, 20], [10, 20]) def testOneDimensionalWithMaxlen(self): - with self.test_session(): + with self.cached_session(): res = array_ops.sequence_mask(constant_op.constant([1, 3, 2]), 5) self.assertAllEqual(res.get_shape(), [3, 5]) self.assertAllEqual( @@ -1081,7 +1081,7 @@ class SequenceMaskTest(test_util.TensorFlowTestCase): @test_util.enable_c_shapes def testOneDimensionalDtypeWithoutMaxlen(self): - with self.test_session(): + with self.cached_session(): # test dtype and default maxlen: res = array_ops.sequence_mask(constant_op.constant([0, 1, 4]), dtype=dtypes.float32) @@ -1092,7 +1092,7 @@ class SequenceMaskTest(test_util.TensorFlowTestCase): @test_util.enable_c_shapes def testOneDimensionalWithoutMaxlen(self): - with self.test_session(): + with self.cached_session(): res = array_ops.sequence_mask( constant_op.constant([0, 1, 4])) self.assertAllEqual(res.get_shape().as_list(), [3, 4]) @@ -1104,7 +1104,7 @@ class SequenceMaskTest(test_util.TensorFlowTestCase): @test_util.enable_c_shapes def testTwoDimensional(self): - with self.test_session(): + with self.cached_session(): res = array_ops.sequence_mask(constant_op.constant([[1, 3, 2]]), 5) self.assertAllEqual(res.get_shape(), [1, 3, 5]) self.assertAllEqual(res.eval(), [[[True, False, False, False, False], [ @@ -1137,7 +1137,7 @@ class SequenceMaskTest(test_util.TensorFlowTestCase): [[True, False, False, False, False], [True, True, True, False, False], [True, True, False, False, False]]) - with self.test_session(): + with self.cached_session(): check_dtypes(dtypes.int32, dtypes.int32) check_dtypes(dtypes.int32, dtypes.int64) check_dtypes(dtypes.int64, dtypes.int32) @@ -1216,7 +1216,7 @@ class UnravelIndexTest(test_util.TensorFlowTestCase): # TODO(b/73086570): Reenable test. @unittest.skip("Test does not pass internally.") def testUnravelIndex(self): - with self.test_session(): + with self.cached_session(): for dtype in [dtypes.int32, dtypes.int64]: indices_1 = constant_op.constant(1621, dtype=dtype) dims_1 = constant_op.constant([6, 7, 8, 9], dtype=dtype) @@ -1237,13 +1237,13 @@ class UnravelIndexTest(test_util.TensorFlowTestCase): class GuaranteeConstOpTest(test_util.TensorFlowTestCase): def testSimple(self): - with self.test_session(): + with self.cached_session(): a = array_ops.constant(10) guarantee_a = array_ops.guarantee_const(a) self.assertEqual(10, guarantee_a.eval()) def testVariables(self): - with self.test_session() as sess: + with self.cached_session() as sess: for use_resource in [False, True]: a = variable_scope.get_variable( "var_{}".format(use_resource), [], @@ -1254,7 +1254,7 @@ class GuaranteeConstOpTest(test_util.TensorFlowTestCase): self.assertEqual(10.0, guarantee_a.eval()) def testResourceRejection(self): - with self.test_session() as sess: + with self.cached_session() as sess: a = variable_scope.get_variable( "resource_var", [], initializer=init_ops.constant_initializer(10.0), |