hyperiax.Tree

class hyperiax.Tree(topology, schema, data)[source]

Bases: object

A topology + a typed dict of (N, *trailing) arrays.

Construction is always functional: every “mutator” returns a new Tree sharing the same Topology and (usually) Schema, with replaced data.

Data fields are reachable two ways: tree['value'] (dict-style, the safe form when the field name is dynamic or collides with a reserved name) and tree.value (attribute-style, the canonical form mirroring node.value / children.value inside a sweep).

Parameters:
__init__(topology, schema, data)
Parameters:
Return type:

None

Methods

__init__(topology, schema, data)

drop(*names)

Drop fields; returns a Tree with reduced schema and data.

empty(topology, schema)

Allocate a Tree of zeros with the declared schema.

from_data(topology, data)

Build a Tree from an existing data dict; schema is inferred from arrays.

set(**fields)

Replace whole fields.

update(**fields)

Add brand-new fields.

Attributes

at

tree.at[indices].set(field=values).

size

topology

schema

data

topology: Topology
schema: Schema
data: dict
classmethod empty(topology, schema)[source]

Allocate a Tree of zeros with the declared schema.

Return type:

Tree

Parameters:
classmethod from_data(topology, data)[source]

Build a Tree from an existing data dict; schema is inferred from arrays.

Return type:

Tree

Parameters:
property size: int
set(**fields)[source]

Replace whole fields. Each value must already match (N, *spec.shape).

Return type:

Tree

Parameters:

fields (Array)

property at: _AtAccessor

tree.at[indices].set(field=values).

Mirrors jax.numpy.ndarray.at. The returned indexer supports set, add, multiply, min, max (all take fields as keyword arguments and return a new Tree) and get (returns a dict of every field evaluated at indices).

Type:

JAX-style scatter accessor

update(**fields)[source]

Add brand-new fields. Values can be a FieldSpec, a shape tuple, or an array.

Note: this changes the pytree structure and will invalidate any JIT caches keyed on the previous structure. Prefer Tree.empty(topo, full_schema) when you know all the fields up front (the typical case in a sweep pipeline).

Return type:

Tree

drop(*names)[source]

Drop fields; returns a Tree with reduced schema and data.

Return type:

Tree

Parameters:

names (str)