Remove @test_util.run_deprecated_v1 in inplace_ops_test.py
PiperOrigin-RevId: 324106097 Change-Id: I1b527f05ef13b305cb5937d303da5f6dc8eb6f39
This commit is contained in:
parent
9d51422403
commit
9186d42865
@ -31,10 +31,9 @@ from tensorflow.python.platform import test as test_lib
|
|||||||
|
|
||||||
class InplaceOpsTest(test_util.TensorFlowTestCase):
|
class InplaceOpsTest(test_util.TensorFlowTestCase):
|
||||||
|
|
||||||
@test_util.run_deprecated_v1
|
|
||||||
def testBasicUpdate(self):
|
def testBasicUpdate(self):
|
||||||
for dtype in [dtypes.float32, dtypes.int32, dtypes.int64]:
|
for dtype in [dtypes.float32, dtypes.int32, dtypes.int64]:
|
||||||
with self.session(use_gpu=True):
|
with test_util.use_gpu():
|
||||||
x = array_ops.ones([7, 3], dtype)
|
x = array_ops.ones([7, 3], dtype)
|
||||||
y = np.ones([7, 3], dtype.as_numpy_dtype)
|
y = np.ones([7, 3], dtype.as_numpy_dtype)
|
||||||
self.assertAllClose(x, y)
|
self.assertAllClose(x, y)
|
||||||
@ -49,9 +48,8 @@ class InplaceOpsTest(test_util.TensorFlowTestCase):
|
|||||||
y[5, :] = 7
|
y[5, :] = 7
|
||||||
self.assertAllClose(x, y)
|
self.assertAllClose(x, y)
|
||||||
|
|
||||||
@test_util.run_deprecated_v1
|
|
||||||
def testBasicUpdateBool(self):
|
def testBasicUpdateBool(self):
|
||||||
with self.session(use_gpu=True):
|
with test_util.use_gpu():
|
||||||
x = array_ops.ones([7, 3], dtypes.bool)
|
x = array_ops.ones([7, 3], dtypes.bool)
|
||||||
y = np.ones([7, 3], dtypes.bool.as_numpy_dtype)
|
y = np.ones([7, 3], dtypes.bool.as_numpy_dtype)
|
||||||
self.assertAllClose(x, y)
|
self.assertAllClose(x, y)
|
||||||
@ -67,10 +65,9 @@ class InplaceOpsTest(test_util.TensorFlowTestCase):
|
|||||||
y[5, :] = False
|
y[5, :] = False
|
||||||
self.assertAllClose(x, y)
|
self.assertAllClose(x, y)
|
||||||
|
|
||||||
@test_util.run_deprecated_v1
|
|
||||||
def testBasicAdd(self):
|
def testBasicAdd(self):
|
||||||
for dtype in [dtypes.float32, dtypes.int32, dtypes.int64]:
|
for dtype in [dtypes.float32, dtypes.int32, dtypes.int64]:
|
||||||
with self.cached_session(use_gpu=True):
|
with test_util.use_gpu():
|
||||||
x = array_ops.ones([7, 3], dtype)
|
x = array_ops.ones([7, 3], dtype)
|
||||||
y = np.ones([7, 3], dtype.as_numpy_dtype)
|
y = np.ones([7, 3], dtype.as_numpy_dtype)
|
||||||
self.assertAllClose(x, y)
|
self.assertAllClose(x, y)
|
||||||
@ -87,10 +84,9 @@ class InplaceOpsTest(test_util.TensorFlowTestCase):
|
|||||||
y[:, :] += 99
|
y[:, :] += 99
|
||||||
self.assertAllClose(x, y)
|
self.assertAllClose(x, y)
|
||||||
|
|
||||||
@test_util.run_deprecated_v1
|
|
||||||
def testBasicSub(self):
|
def testBasicSub(self):
|
||||||
for dtype in [dtypes.float32, dtypes.int32, dtypes.int64]:
|
for dtype in [dtypes.float32, dtypes.int32, dtypes.int64]:
|
||||||
with self.cached_session(use_gpu=True):
|
with test_util.use_gpu():
|
||||||
x = array_ops.ones([7, 3], dtype)
|
x = array_ops.ones([7, 3], dtype)
|
||||||
y = np.ones([7, 3], dtype.as_numpy_dtype)
|
y = np.ones([7, 3], dtype.as_numpy_dtype)
|
||||||
self.assertAllClose(x, y)
|
self.assertAllClose(x, y)
|
||||||
@ -107,9 +103,8 @@ class InplaceOpsTest(test_util.TensorFlowTestCase):
|
|||||||
y[:, :] -= 99
|
y[:, :] -= 99
|
||||||
self.assertAllClose(x, y)
|
self.assertAllClose(x, y)
|
||||||
|
|
||||||
@test_util.run_deprecated_v1
|
|
||||||
def testRandom(self):
|
def testRandom(self):
|
||||||
with self.session(use_gpu=True):
|
with test_util.use_gpu():
|
||||||
d0, d1, d2 = 100, 3, 5
|
d0, d1, d2 = 100, 3, 5
|
||||||
x = array_ops.zeros([d0, d1, d2])
|
x = array_ops.zeros([d0, d1, d2])
|
||||||
y = np.zeros([d0, d1, d2])
|
y = np.zeros([d0, d1, d2])
|
||||||
@ -128,9 +123,8 @@ class InplaceOpsTest(test_util.TensorFlowTestCase):
|
|||||||
y[idx, :] -= val
|
y[idx, :] -= val
|
||||||
self.assertAllClose(x, y)
|
self.assertAllClose(x, y)
|
||||||
|
|
||||||
@test_util.run_deprecated_v1
|
|
||||||
def testRandom1D(self):
|
def testRandom1D(self):
|
||||||
with self.session(use_gpu=True):
|
with test_util.use_gpu():
|
||||||
d0 = 100
|
d0 = 100
|
||||||
x = array_ops.zeros([d0])
|
x = array_ops.zeros([d0])
|
||||||
y = np.zeros([d0])
|
y = np.zeros([d0])
|
||||||
@ -150,7 +144,7 @@ class InplaceOpsTest(test_util.TensorFlowTestCase):
|
|||||||
self.assertAllClose(x, y)
|
self.assertAllClose(x, y)
|
||||||
|
|
||||||
def testAlias(self):
|
def testAlias(self):
|
||||||
with self.session(use_gpu=True) as sess:
|
with test_util.use_gpu():
|
||||||
x = array_ops.ones([2, 3])
|
x = array_ops.ones([2, 3])
|
||||||
y = inplace_ops.alias_inplace_add(x, [0], [[1, 2, 3]])
|
y = inplace_ops.alias_inplace_add(x, [0], [[1, 2, 3]])
|
||||||
with ops.control_dependencies([y]):
|
with ops.control_dependencies([y]):
|
||||||
@ -159,50 +153,48 @@ class InplaceOpsTest(test_util.TensorFlowTestCase):
|
|||||||
self.assertAllClose(vy, vz)
|
self.assertAllClose(vy, vz)
|
||||||
|
|
||||||
def testError(self):
|
def testError(self):
|
||||||
with self.cached_session():
|
with self.assertRaisesRegex(errors.InvalidArgumentError,
|
||||||
with self.assertRaisesRegex(errors.InvalidArgumentError,
|
"must be a vector"):
|
||||||
"must be a vector"):
|
_ = self.evaluate(inplace_ops.inplace_update([[1.]], [[0]], [[10]]))
|
||||||
_ = inplace_ops.inplace_update([[1.]], [[0]], [[10]]).eval()
|
with self.assertRaisesRegex(errors.InvalidArgumentError,
|
||||||
with self.assertRaisesRegex(errors.InvalidArgumentError,
|
"x and v shape doesn't match"):
|
||||||
"x and v shape doesn't match"):
|
_ = self.evaluate(inplace_ops.inplace_update([[1.]], [0], [10]))
|
||||||
_ = inplace_ops.inplace_update([[1.]], [0], [10]).eval()
|
with self.assertRaisesRegex(errors.InvalidArgumentError,
|
||||||
with self.assertRaisesRegex(errors.InvalidArgumentError,
|
"i and x shape doesn't match"):
|
||||||
"i and x shape doesn't match"):
|
_ = self.evaluate(inplace_ops.inplace_update([[1.]], [0, 1], [[10]]))
|
||||||
_ = inplace_ops.inplace_update([[1.]], [0, 1], [[10]]).eval()
|
|
||||||
|
|
||||||
@test_util.run_deprecated_v1
|
|
||||||
def testEmpty(self):
|
def testEmpty(self):
|
||||||
for dtype in [
|
for dtype in [
|
||||||
dtypes.float32, dtypes.float64, dtypes.int32, dtypes.int64, dtypes.bool,
|
dtypes.float32, dtypes.float64, dtypes.int32, dtypes.int64, dtypes.bool,
|
||||||
dtypes.uint8
|
dtypes.uint8
|
||||||
]:
|
]:
|
||||||
with self.cached_session(use_gpu=True):
|
with test_util.use_gpu():
|
||||||
test_shapes = [(), (1,), (2, 3), (0, 2), (2, 3, 5), (2, 0, 5)]
|
test_shapes = [(), (1,), (2, 3), (0, 2), (2, 3, 5), (2, 0, 5)]
|
||||||
for shape in test_shapes:
|
for shape in test_shapes:
|
||||||
val = inplace_ops.empty(shape, dtype).eval()
|
val = self.evaluate(inplace_ops.empty(shape, dtype))
|
||||||
self.assertEqual(val.shape, shape)
|
self.assertEqual(val.shape, shape)
|
||||||
self.assertEqual(val.dtype, dtype.as_numpy_dtype)
|
self.assertEqual(val.dtype, dtype.as_numpy_dtype)
|
||||||
val = inplace_ops.empty(shape, dtype, init=True).eval()
|
val = self.evaluate(inplace_ops.empty(shape, dtype, init=True))
|
||||||
self.assertEqual(val.shape, shape)
|
self.assertEqual(val.shape, shape)
|
||||||
self.assertEqual(val.dtype, dtype.as_numpy_dtype)
|
self.assertEqual(val.dtype, dtype.as_numpy_dtype)
|
||||||
self.assertAllEqual(val, np.zeros(shape, dtype.as_numpy_dtype))
|
self.assertAllEqual(val, np.zeros(shape, dtype.as_numpy_dtype))
|
||||||
val = inplace_ops.empty_like(array_ops.zeros(shape, dtype)).eval()
|
val = self.evaluate(
|
||||||
|
inplace_ops.empty_like(array_ops.zeros(shape, dtype)))
|
||||||
self.assertEqual(val.shape, shape)
|
self.assertEqual(val.shape, shape)
|
||||||
self.assertEqual(val.dtype, dtype.as_numpy_dtype)
|
self.assertEqual(val.dtype, dtype.as_numpy_dtype)
|
||||||
val = inplace_ops.empty_like(
|
val = self.evaluate(inplace_ops.empty_like(
|
||||||
array_ops.zeros(shape, dtype), init=True).eval()
|
array_ops.zeros(shape, dtype), init=True))
|
||||||
self.assertEqual(val.shape, shape)
|
self.assertEqual(val.shape, shape)
|
||||||
self.assertEqual(val.dtype, dtype.as_numpy_dtype)
|
self.assertEqual(val.dtype, dtype.as_numpy_dtype)
|
||||||
self.assertAllEqual(val, np.zeros(shape, dtype.as_numpy_dtype))
|
self.assertAllEqual(val, np.zeros(shape, dtype.as_numpy_dtype))
|
||||||
|
|
||||||
with self.cached_session(use_gpu=True):
|
with test_util.use_gpu():
|
||||||
val = inplace_ops.empty((1, 2), dtypes.string, init=True).eval()
|
val = self.evaluate(inplace_ops.empty((1, 2), dtypes.string, init=True))
|
||||||
self.assertEqual(val.tolist(), [[b"", b""]])
|
self.assertEqual(val.tolist(), [[b"", b""]])
|
||||||
|
|
||||||
val = inplace_ops.empty((1, 2), dtypes.string, init=False).eval()
|
val = self.evaluate(inplace_ops.empty((1, 2), dtypes.string, init=False))
|
||||||
self.assertEqual(val.tolist(), [[b"", b""]])
|
self.assertEqual(val.tolist(), [[b"", b""]])
|
||||||
|
|
||||||
@test_util.run_deprecated_v1
|
|
||||||
def testInplaceOpOnEmptyTensors(self):
|
def testInplaceOpOnEmptyTensors(self):
|
||||||
op_fns = [
|
op_fns = [
|
||||||
inplace_ops.inplace_add,
|
inplace_ops.inplace_add,
|
||||||
@ -211,7 +203,7 @@ class InplaceOpsTest(test_util.TensorFlowTestCase):
|
|||||||
]
|
]
|
||||||
for dtype in [dtypes.float32, dtypes.int32, dtypes.int64]:
|
for dtype in [dtypes.float32, dtypes.int32, dtypes.int64]:
|
||||||
for op_fn in op_fns:
|
for op_fn in op_fns:
|
||||||
with self.cached_session(use_gpu=True):
|
with test_util.use_gpu():
|
||||||
x = array_ops.zeros([7, 0], dtype)
|
x = array_ops.zeros([7, 0], dtype)
|
||||||
y = np.zeros([7, 0], dtype.as_numpy_dtype)
|
y = np.zeros([7, 0], dtype.as_numpy_dtype)
|
||||||
self.assertAllClose(x, y)
|
self.assertAllClose(x, y)
|
||||||
|
Loading…
Reference in New Issue
Block a user