(self, tree)
| 198 | return self.slot_map(node.kwargs) |
| 199 | |
| 200 | def slot_map(self, tree): |
| 201 | leaves, spec = pytree.tree_flatten(tree) |
| 202 | new_leaves = [] |
| 203 | for a in leaves: |
| 204 | if isinstance(a, Node): |
| 205 | # Use make_or_get_slots which handles both single and multi-output nodes. |
| 206 | # For single-output nodes, returns a 1-tuple; for multi-output, returns n-tuple. |
| 207 | # We unwrap single-element tuples for convenience. |
| 208 | slots = self.make_or_get_slots(a) |
| 209 | if len(slots) == 1: |
| 210 | new_leaves.append(slots[0]) |
| 211 | else: |
| 212 | new_leaves.append(slots) |
| 213 | else: |
| 214 | new_leaves.append(a) |
| 215 | |
| 216 | for a in new_leaves: |
| 217 | if isinstance(a, Slot): |
| 218 | assert self.slot_manager.is_alive( |
| 219 | a |
| 220 | ), f"Slot {a} is not alive; it was either already freed or never created" |
| 221 | |
| 222 | return pytree.tree_unflatten(new_leaves, spec) |
| 223 | |
| 224 | def make_or_get_slots( |
| 225 | self, node: Node, id_space: IdSpace = IdSpace.Temp |
no test coverage detected