remove v1 decorator

PiperOrigin-RevId: 324043175
Change-Id: I0bc404d55da56b77c5a54a8235bb5601ad5e70d9
This commit is contained in:
Yanhua Sun 2020-07-30 11:21:22 -07:00 committed by TensorFlower Gardener
parent cdbd96f307
commit 43154abec0

View File

@ -27,6 +27,7 @@ from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import func_graph
from tensorflow.python.framework import indexed_slices
from tensorflow.python.framework import ops
from tensorflow.python.framework import sparse_tensor
from tensorflow.python.framework import tensor_shape
from tensorflow.python.framework import tensor_util
@ -816,8 +817,8 @@ class ConstantValueTest(test.TestCase):
tf_val = constant_op.constant(np_val)
self.assertAllClose(np_val, tensor_util.constant_value(tf_val))
@test_util.run_deprecated_v1
def testUnknown(self):
with ops.Graph().as_default():
tf_val = gen_state_ops.variable(
shape=[3, 4, 7],
dtype=dtypes.float32,
@ -845,19 +846,17 @@ class ConstantValueTest(test.TestCase):
c_val = tensor_util.constant_value(tf_val)
self.assertEqual(6, c_val)
@test_util.run_deprecated_v1
def testSizeOfScalar(self):
tf_val = array_ops.size(constant_op.constant(0.0))
c_val = tensor_util.constant_value(tf_val)
self.assertEqual(1, c_val)
self.assertEqual(np.ndarray, type(c_val))
self.assertIn(type(c_val), [np.ndarray, np.int32])
@test_util.run_deprecated_v1
def testRank(self):
tf_val = array_ops.rank(constant_op.constant(0.0, shape=[1, 2, 3]))
c_val = tensor_util.constant_value(tf_val)
self.assertEqual(np.ndarray, type(c_val))
self.assertIn(type(c_val), [np.ndarray, np.int32])
self.assertEqual((), c_val.shape)
self.assertEqual(3, c_val)
@ -868,7 +867,7 @@ class ConstantValueTest(test.TestCase):
0.0, shape=[1, 2, 3]), optimize=False)
c_val = tensor_util.constant_value(tf_val)
self.assertEqual(np.ndarray, type(c_val))
self.assertIn(type(c_val), [np.ndarray, np.int32])
self.assertEqual((), c_val.shape)
self.assertEqual(3, c_val)
self.assertEqual([3], c_val)
@ -884,7 +883,6 @@ class ConstantValueTest(test.TestCase):
c_val = tensor_util.constant_value(tf_val)
self.assertAllClose(np_val.astype(np.float64), c_val)
@test_util.run_deprecated_v1
def testConcat(self):
np_val = np.random.rand(3, 4, 7).astype(np.float32)
tf_val = array_ops.concat(
@ -892,6 +890,8 @@ class ConstantValueTest(test.TestCase):
c_val = tensor_util.constant_value(tf_val)
self.assertAllClose(np_val, c_val)
# This test needs a placeholder which means we need to construct a graph.
with ops.Graph().as_default():
tf_val = array_ops.concat(
[np_val[0, :, :], np_val[1, :, :], np_val[2, :, :]],
array_ops.placeholder(dtypes.int32))
@ -899,12 +899,12 @@ class ConstantValueTest(test.TestCase):
self.assertIs(None, c_val)
tf_val = array_ops.concat([
np_val[0, :, :], array_ops.placeholder(dtypes.float32), np_val[2, :, :]
np_val[0, :, :],
array_ops.placeholder(dtypes.float32), np_val[2, :, :]
], 1)
c_val = tensor_util.constant_value(tf_val)
self.assertIs(None, c_val)
@test_util.run_deprecated_v1
def testPack_Axis0(self):
inputs = [np.random.rand(4, 7) for _ in range(3)]
np_val = np.array(inputs)
@ -912,65 +912,72 @@ class ConstantValueTest(test.TestCase):
c_val = tensor_util.constant_value(tf_val)
self.assertAllClose(np_val, c_val)
# This test needs a placeholder which means we need to construct a graph.
with ops.Graph().as_default():
tf_val = array_ops.stack(
[inputs[0], array_ops.placeholder(dtypes.float32), inputs[2]])
[inputs[0],
array_ops.placeholder(dtypes.float32), inputs[2]])
c_val = tensor_util.constant_value(tf_val)
self.assertIs(None, c_val)
@test_util.run_deprecated_v1
def testPack_Axis1(self):
# This test needs a placeholder which means we need to construct a graph.
with ops.Graph().as_default():
inputs = [np.random.rand(4, 7) for _ in range(3)]
tf_val = array_ops.stack(inputs, axis=1)
c_val = tensor_util.constant_value(tf_val)
self.assertIsNone(c_val)
tf_val = array_ops.stack(
[inputs[0], array_ops.placeholder(dtypes.float32), inputs[2]], axis=1)
[inputs[0],
array_ops.placeholder(dtypes.float32), inputs[2]], axis=1)
c_val = tensor_util.constant_value(tf_val)
self.assertIs(None, c_val)
@test_util.run_deprecated_v1
def testPack_Partial_Axis0(self):
input_ = np.random.rand(4, 7)
# This test needs a placeholder which means we need to construct a graph.
with ops.Graph().as_default():
tf_val = array_ops.stack([input_, array_ops.placeholder(dtypes.float32)])
c_val = tensor_util.constant_value(tf_val, partial=True)
self.assertAllClose(input_, c_val[0])
self.assertIsNone(c_val[1])
@test_util.run_deprecated_v1
def testPack_Partial_Axis1(self):
input_ = np.random.rand(4, 7)
tf_val = array_ops.stack([input_, array_ops.placeholder(dtypes.float32)],
axis=1)
# This test needs a placeholder which means we need to construct a graph.
with ops.Graph().as_default():
tf_val = array_ops.stack(
[input_, array_ops.placeholder(dtypes.float32)], axis=1)
c_val = tensor_util.constant_value(tf_val, partial=True)
self.assertIsNone(c_val)
@test_util.run_deprecated_v1
def testUnpack_Axis0(self):
inputs = np.random.rand(3, 4, 7)
tf_vals = array_ops.unstack(inputs)
c_vals = [tensor_util.constant_value(x) for x in tf_vals]
self.assertAllClose(inputs, c_vals)
@test_util.run_deprecated_v1
def testUnpack_Partial_Axis0(self):
input_ = np.random.rand(4, 7)
# This test needs a placeholder which means we need to construct a graph.
with ops.Graph().as_default():
packed = array_ops.stack([input_, array_ops.placeholder(dtypes.float32)])
tf_vals = array_ops.unstack(packed)
c_vals = [tensor_util.constant_value(x, partial=True) for x in tf_vals]
self.assertAllClose(input_, c_vals[0])
self.assertIsNone(c_vals[1])
@test_util.run_deprecated_v1
def testSplit_Axis0(self):
inputs = np.random.rand(6, 5, 7)
tf_vals = array_ops.split(inputs, 3)
c_vals = [tensor_util.constant_value(x) for x in tf_vals]
self.assertAllClose(np.split(inputs, 3), c_vals)
@test_util.run_deprecated_v1
def testSplit_Partial_Axis0(self):
input_ = np.random.rand(4, 7)
# This test needs a placeholder which means we need to construct a graph.
with ops.Graph().as_default():
placeholder = array_ops.placeholder(dtypes.float32, shape=(4, 7))
# it'd be better to use concat here, but concat doesn't support partial
packed = array_ops.stack([input_, placeholder])
@ -1079,29 +1086,32 @@ class ConstantValueAsShapeTest(test.TestCase):
c_val = tensor_util.constant_value_as_shape(tf_val)
self.assertEqual([None, 1, None], c_val.as_list())
@test_util.run_deprecated_v1
def testPack(self):
# This test needs a placeholder which means we need to construct a graph.
with ops.Graph().as_default():
tf_val = array_ops.stack(
[constant_op.constant(16), 37, array_ops.placeholder(dtypes.int32)])
[constant_op.constant(16), 37,
array_ops.placeholder(dtypes.int32)])
c_val = tensor_util.constant_value_as_shape(tf_val)
self.assertEqual([16, 37, None], c_val.as_list())
@test_util.run_deprecated_v1
def testConcat(self):
# This test needs a placeholder which means we need to construct a graph.
with ops.Graph().as_default():
tf_val = array_ops.concat(
[[16, 37], array_ops.placeholder(
dtypes.int32, shape=(2,))], 0)
[[16, 37], array_ops.placeholder(dtypes.int32, shape=(2,))], 0)
c_val = tensor_util.constant_value_as_shape(tf_val)
self.assertEqual([16, 37, None, None], c_val.as_list())
tf_val = array_ops.concat(
[[16, 37], array_ops.placeholder(
dtypes.int32, shape=(1,)), [48]], 0)
[[16, 37],
array_ops.placeholder(dtypes.int32, shape=(1,)), [48]], 0)
c_val = tensor_util.constant_value_as_shape(tf_val)
self.assertEqual([16, 37, None, 48], c_val.as_list())
@test_util.run_deprecated_v1
def testSlice(self):
# This test needs a placeholder which means we need to construct a graph.
with ops.Graph().as_default():
tf_val = array_ops.placeholder(dtypes.int32, shape=(4,))[0:2]
c_val = tensor_util.constant_value_as_shape(tf_val)
self.assertEqual([None, None], c_val.as_list())
@ -1118,9 +1128,11 @@ class ConstantValueAsShapeTest(test.TestCase):
self.assertEqual([20], c_val.as_list())
# [1, 2, 16, 37, None, 48]
# This test needs a placeholder which means we need to construct a graph.
with ops.Graph().as_default():
tf_val_orig = array_ops.concat(
[[1, 2, 16, 37], array_ops.placeholder(
dtypes.int32, shape=(1,)), [48]], 0)
[[1, 2, 16, 37],
array_ops.placeholder(dtypes.int32, shape=(1,)), [48]], 0)
# begin: no end
tf_val = tf_val_orig[2:]
@ -1168,8 +1180,8 @@ class ConstantValueAsShapeTest(test.TestCase):
self.assertEqual([None, None, None], c_val.as_list())
# Do not support shape inference for tensor slices.
tf_val = constant_op.constant([10, 20, 30])[
array_ops.placeholder(dtypes.int32, shape=()):]
tf_val = constant_op.constant(
[10, 20, 30])[array_ops.placeholder(dtypes.int32, shape=()):]
c_val = tensor_util.constant_value_as_shape(tf_val)
self.assertEqual(tensor_shape.unknown_shape(), c_val)
@ -1190,14 +1202,14 @@ class MaybeSetStaticShapeTest(test.TestCase):
finally:
tensor_util._ENABLE_MAYBE_SET_STATIC_SHAPE = flag_old
@test_util.run_deprecated_v1
def testMaybeSetStaticShape(self):
shape = constant_op.constant([2, 5], dtype=dtypes.int32)
def reshape():
v = array_ops.zeros([10])
return array_ops.reshape(v, shape)
# This test needs a placeholder which means we need to construct a graph.
with ops.Graph().as_default():
with self.disableSetStaticShape():
graph_without_shape_propagation = func_graph.func_graph_from_py_func(
"without_shape_propagation", reshape, [], {})
@ -1207,7 +1219,6 @@ class MaybeSetStaticShapeTest(test.TestCase):
[op.type for op in graph_without_shape_propagation.get_operations()],
[op.type for op in graph_with_shape_propagation.get_operations()])
@test_util.run_deprecated_v1
def testMaybeSetStaticShapeScalarShape(self):
def reshape():