to_tree#
- seli.to_tree(obj: None | bool | int | float | str | type | Array | ShapeDtypeStruct | list | dict | Module | Any)[source]#
Convert shared/cyclic references into a PathKeys, the result is a tree.
This function transforms complex nested data structures that may contain shared references (the same object referenced multiple times) or cyclic references (loops in the reference graph) into a tree structure. Instead of maintaining the actual shared or cyclic references, it replaces them with path references.
- Parameters:
obj (NodeType) – The input object to convert to a tree. Can be any supported type: dictionaries, lists, Module objects, or leaf values (None, bool, int, float, str, or jax.Array).
- Returns:
A tree-structured version of the input, with all shared and cyclic references replaced by path references.
- Return type:
NodeType
Notes
This function is useful for serializing complex object graphs or visualizing structures with cycles.
Path references can be used to reconstruct the original structure if needed.
The function uses dfs_map internally to traverse the structure.