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

update

update()

max.experimental.tree_utils.update(tree, state, *, leaf=None, shared=False)

source

Writes path-keyed values into tree, in place.

The counterpart of paths(), taking the same knobs. Only leaves are written, and an unnamed leaf is left alone.

Parameters:

  • tree (Any) – The tree to write into. Mutated.
  • state (Mapping[str, Any]) – The values to write, keyed by dotted path as paths() returns them.
  • leaf (type | tuple[type, ...] | Callable[[Any], bool] | None) – Where the walk stops, and so what counts as a writable position.
  • shared (bool) – Whether a value reachable by two paths is one leaf or two. Set, one write reaches every path to it, and the tie survives.

Returns:

tree itself, or a rebuilt root when the root is a tuple.

Raises:

  • TypeError – If a value must be written under a positional key and its node declares no __tree_setattr__.
  • ValueError – If some entry in state names no leaf in tree.

Return type:

Any