[X] I have searched the Issue Tracker that this hasn't already been reported. (comment there if it has.)
Motivation
Currently, we can only create PyTreeSpec instances via optree.tree_flatten(...), optree.tree_structure(...), or similar APIs. It requires the user to get a pytree first and then flatten it.
Now we only have:
treespec_leaf
treespec_none
treespec_tuple
functions to create PyTreeSpec instances via its children treespecs. Some primitive Python types (e.g., list, dict) are not supported yet.
Required prerequisites
Motivation
Currently, we can only create
PyTreeSpec
instances viaoptree.tree_flatten(...)
,optree.tree_structure(...)
, or similar APIs. It requires the user to get a pytree first and then flatten it.Now we only have:
treespec_leaf
treespec_none
treespec_tuple
functions to create
PyTreeSpec
instances via its children treespecs. Some primitive Python types (e.g.,list
,dict
) are not supported yet.Solution
Add more constructor functions, e.g.:
treespec_list
treespec_dict
treespec_namedtuple
treespec_ordereddict
treespec_defaultdict
treespec_deque
treespec_structseq
treespec_custom
Alternatives
No response
Additional context
No response