archimedes.tree.structureΒΆ

archimedes.tree.structure(tree: Tree, is_leaf: Callable[[Any], bool] | None = None) TreeDefΒΆ

Extract the structure of a tree without the leaf values.

Returns a TreeDef that describes the structure of the tree, which can be used with tree_unflatten to reconstruct a tree with new leaf values.

Parameters:
  • tree (Tree) – A tree whose structure is to be determined.

  • is_leaf (callable, optional) – A function that takes a tree node as input and returns a boolean indicating whether it should be considered a leaf.

Returns:

treedef – A tree definition that describes the structure of the input tree.

Return type:

TreeDef

See also

tree_flatten

Flatten a tree into a list of leaves and a treedef

tree_unflatten

Reconstruct a tree from leaves and a treedef