IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).

Python function

unflatten

unflatten()

max.experimental.tree_utils.unflatten(treedef, leaves)

source

Rebuilds a tree from a structure and its leaves.

The inverse of flatten(), always building a fresh tree.

Parameters:

  • treedef (TreeDef) – The structure, as flatten() reported it.
  • leaves (Iterable[Any]) – Exactly one value per leaf slot, left to right.

Returns:

The rebuilt tree.

Raises:

  • TypeError – If a cycle closes through a node whose class declares no __tree_empty__.
  • ValueError – If the leaf count does not match the structure, or if treedef did not come from flatten().

Return type:

Any