aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/contrib/framework
diff options
context:
space:
mode:
authorGravatar Alexandre Passos <apassos@google.com>2018-07-17 07:47:27 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-07-17 07:50:46 -0700
commite1fb7a248bb2d932a0bed6fc1d2d9e3d91b50e89 (patch)
treebb99a37dc720eb743dc5a0170dc84265b2da1eaa /tensorflow/contrib/framework
parent2bdc5f12a1e66fd851e2621889c743c3b8da65e5 (diff)
Makes Variable an abstract base class with a factory-constructing metaclass.
The metaclass, when asked to make instances of Variable, will loop over a scope of creator functions calling them, before finally bottoming out on a function which constructs a subclass of Variable, which goes through the normal route. This allows us to split Variable from RefVariable and to, in a follow-up CL, add a use_resource argument to the Variable constructor so it can also return ResourceVariable. This is the minimal change to get things working; it does not expose the creator stack or add the use_resource argument. PiperOrigin-RevId: 204910138
Diffstat (limited to 'tensorflow/contrib/framework')
-rw-r--r--tensorflow/contrib/framework/python/ops/variables_test.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/tensorflow/contrib/framework/python/ops/variables_test.py b/tensorflow/contrib/framework/python/ops/variables_test.py
index 7e0c7dbec1..3c44630a51 100644
--- a/tensorflow/contrib/framework/python/ops/variables_test.py
+++ b/tensorflow/contrib/framework/python/ops/variables_test.py
@@ -106,8 +106,9 @@ class LocalVariableTest(test.TestCase):
def testResourceVariable(self):
a = variables_lib2.local_variable(0)
b = variables_lib2.local_variable(0, use_resource=True)
- self.assertEqual(type(a), variables_lib.Variable)
- self.assertEqual(type(b), resource_variable_ops.ResourceVariable)
+ self.assertTrue(isinstance(a, variables_lib.Variable))
+ self.assertFalse(isinstance(a, resource_variable_ops.ResourceVariable))
+ self.assertTrue(isinstance(b, resource_variable_ops.ResourceVariable))
class GlobalVariableTest(test.TestCase):
@@ -176,8 +177,9 @@ class GlobalVariableTest(test.TestCase):
def testResourceVariable(self):
a = variables_lib2.global_variable(0)
b = variables_lib2.global_variable(0, use_resource=True)
- self.assertEqual(type(a), variables_lib.Variable)
- self.assertEqual(type(b), resource_variable_ops.ResourceVariable)
+ self.assertTrue(isinstance(a, variables_lib.Variable))
+ self.assertFalse(isinstance(a, resource_variable_ops.ResourceVariable))
+ self.assertTrue(isinstance(b, resource_variable_ops.ResourceVariable))
class GlobalStepTest(test.TestCase):