(self)
| 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): |
nothing calls this directly
no test coverage detected