()
| 2038 | |
| 2039 | @eager_function.defun |
| 2040 | def defun(): |
| 2041 | ops.add_to_collection("int", 1) |
| 2042 | ops.add_to_collection("tensor", constant_op.constant(2)) |
| 2043 | |
| 2044 | @eager_function.defun |
| 2045 | def inner_defun(): |
| 2046 | self.assertEqual(ops.get_collection("int"), [1]) |
| 2047 | three = ops.get_collection("tensor")[0] + ops.get_collection("int")[0] |
| 2048 | ops.add_to_collection("int", 2) |
| 2049 | self.assertEqual(ops.get_collection("int"), [1, 2]) |
| 2050 | ops.add_to_collection("foo", "bar") |
| 2051 | self.assertEqual(ops.get_collection("foo"), ["bar"]) |
| 2052 | return three |
| 2053 | |
| 2054 | self.assertEqual(ops.get_collection("int"), [1]) |
| 2055 | three = inner_defun() |
| 2056 | self.assertEqual(ops.get_collection("int"), [1]) |
| 2057 | self.assertEqual(ops.get_collection("foo"), []) |
| 2058 | return three |
| 2059 | |
| 2060 | three = defun() |
| 2061 | self.assertEqual(three.numpy(), 3) |
no test coverage detected