MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / testMap_Scoped

Method testMap_Scoped

tensorflow/python/kernel_tests/map_fn_test.py:88–117  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

86
87 @test_util.run_deprecated_v1
88 def testMap_Scoped(self):
89 with self.cached_session() as sess:
90
91 def double_scoped(x):
92 """2x with a dummy 2 that is scoped."""
93 with variable_scope.variable_scope("body"):
94 # Dummy variable, just to check that scoping works as intended.
95 two = variable_scope.get_variable(
96 "two", [],
97 dtype=dtypes.int32,
98 initializer=init_ops.constant_initializer(2))
99 return math_ops.multiply(x, two)
100
101 with variable_scope.variable_scope("root") as varscope:
102 elems = constant_op.constant([1, 2, 3, 4, 5, 6], name="data")
103 doubles = np.array([2 * x for x in [1, 2, 3, 4, 5, 6]])
104
105 r = map_fn.map_fn(double_scoped, elems)
106 # Check that we have the one variable we asked for here.
107 self.assertEqual(len(variables.trainable_variables()), 1)
108 self.assertEqual(variables.trainable_variables()[0].name,
109 "root/body/two:0")
110 sess.run([variables.global_variables_initializer()])
111 self.assertAllEqual(doubles, self.evaluate(r))
112
113 # Now let's reuse our single variable.
114 varscope.reuse_variables()
115 r = map_fn.map_fn(double_scoped, elems)
116 self.assertEqual(len(variables.trainable_variables()), 1)
117 self.assertAllEqual(doubles, self.evaluate(r))
118
119 @test_util.run_deprecated_v1
120 def testMap_Grad(self):

Callers

nothing calls this directly

Calls 9

variable_scopeMethod · 0.80
reuse_variablesMethod · 0.80
cached_sessionMethod · 0.45
constantMethod · 0.45
map_fnMethod · 0.45
trainable_variablesMethod · 0.45
runMethod · 0.45
assertAllEqualMethod · 0.45
evaluateMethod · 0.45

Tested by

no test coverage detected