(self, cycles)
| 1046 | self.assertEqual(3, len(imported.variables)) |
| 1047 | |
| 1048 | def test_functions_list(self, cycles): |
| 1049 | root = tracking.AutoTrackable() |
| 1050 | v1 = variables.Variable(1.) |
| 1051 | root.losses = [def_function.function(lambda: math_ops.reduce_sum(v1 ** 2))] |
| 1052 | root.variables = [v1] |
| 1053 | |
| 1054 | @def_function.function |
| 1055 | def _v2_loss(): |
| 1056 | if len(root.variables) == 1: |
| 1057 | v2 = variables.Variable(2.) |
| 1058 | root.variables.append(v2) |
| 1059 | return math_ops.reduce_sum(root.variables[1] ** 2) |
| 1060 | |
| 1061 | root.losses.append(_v2_loss) |
| 1062 | self.assertAllClose([1., 4.], [loss() for loss in root.losses]) |
| 1063 | imported = cycle(root, cycles) |
| 1064 | self.assertAllClose([1., 4.], [loss() for loss in imported.losses]) |
| 1065 | imported.variables[0].assign(3.) |
| 1066 | imported.variables[1].assign(4.) |
| 1067 | self.assertAllClose([9., 16.], [loss() for loss in imported.losses]) |
| 1068 | |
| 1069 | def test_captured_constant(self, cycles): |
| 1070 | const = array_ops.zeros([100]) |
nothing calls this directly
no test coverage detected