archimedes.treeΒΆ

Utilities for working with hierarchical tree-structured data.

Functions

all(tree[, is_leaf])

Check if all leaves in the tree evaluate to True.

field([static, metadata])

Create a field specification with struct-related metadata.

fields(class_or_instance)

Return a tuple describing the fields of this dataclass.

flatten(x[, is_leaf])

Flatten a tree into a list of leaves and a treedef.

is_leaf(x)

Check if a value is a leaf in a tree.

is_struct(obj)

Check if an object is a registered struct class.

leaves(tree[, is_leaf])

Extract all leaf values from a tree.

map(f, tree, *rest[, is_leaf])

Apply a function to each leaf in a tree.

ravel(tree)

Flatten a tree to a single 1D array.

reduce(function, tree, initializer[, is_leaf])

Reduce a tree to a single value using a function and initializer.

register_dataclass(nodetype[, data_fields, ...])

Register a dataclass as tree-compatible with customized field handling.

register_struct(ty, to_iter, from_iter)

Register a custom type as a tree-compatible dataclass.

replace(obj, /, **changes)

Return a new object replacing specified fields with new values.

struct([cls])

Decorator to convert a class into a tree-compatible frozen dataclass.

structure(tree[, is_leaf])

Extract the structure of a tree without the leaf values.

unflatten(treedef, xs)

Reconstruct a tree from a list of leaves and a treedef.

Classes

InitVar(type)

StructConfig()

Base class for creating configuration objects with automatic type discrimination.

UnionConfig()

Discriminated union of StructConfig subclasses.