alpenstock.pytree.core
Classes:
| Name | Description |
|---|---|
AttrKey |
|
FlattenFunc |
|
ItemKey |
|
LeafType |
|
PathKey |
|
Registration |
|
TreeDef |
|
TreePath |
|
UnflattenFunc |
|
Functions:
| Name | Description |
|---|---|
is_leaf |
|
register_pytree_node |
Register a custom pytree node type. |
tree_flatten_with_path |
|
tree_unflatten |
|
unregister_pytree_node |
Unregister a custom pytree node type. |
Attributes:
| Name | Type | Description |
|---|---|---|
ChildrenAuxKey |
|
|
PYTREE_REGISTRATIONS |
dict[Type[Any], Registration]
|
|
AttrKey
Bases: PathKey
flowchart TD
alpenstock.pytree.core.AttrKey[AttrKey]
alpenstock.pytree.core.PathKey[PathKey]
alpenstock.pytree.core.PathKey --> alpenstock.pytree.core.AttrKey
click alpenstock.pytree.core.AttrKey href "" "alpenstock.pytree.core.AttrKey"
click alpenstock.pytree.core.PathKey href "" "alpenstock.pytree.core.PathKey"
Methods:
| Name | Description |
|---|---|
__str__ |
|
get |
|
Attributes:
| Name | Type | Description |
|---|---|---|
key |
str
|
|
FlattenFunc
Bases: Protocol
flowchart TD
alpenstock.pytree.core.FlattenFunc[FlattenFunc]
click alpenstock.pytree.core.FlattenFunc href "" "alpenstock.pytree.core.FlattenFunc"
Methods:
| Name | Description |
|---|---|
__call__ |
The function to flatten a pytree node. |
__call__
__call__(obj: Any) -> ChildrenAuxKey
The function to flatten a pytree node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
the pytree node to flatten |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ChildrenAuxKey |
ChildrenAuxKey
|
A tuple of (children, aux, path_keys), where children (tuple[Any, ...]): A tuple of child nodes. aux (Any): auxiliary data needed to reconstruct the node. path_keys (tuple[PathKey, ...]): A tuple of PathKey objects representing the path to each child. |
ItemKey
Bases: PathKey
flowchart TD
alpenstock.pytree.core.ItemKey[ItemKey]
alpenstock.pytree.core.PathKey[PathKey]
alpenstock.pytree.core.PathKey --> alpenstock.pytree.core.ItemKey
click alpenstock.pytree.core.ItemKey href "" "alpenstock.pytree.core.ItemKey"
click alpenstock.pytree.core.PathKey href "" "alpenstock.pytree.core.PathKey"
Methods:
| Name | Description |
|---|---|
__str__ |
|
get |
|
Attributes:
| Name | Type | Description |
|---|---|---|
key |
Any
|
|
LeafType
PathKey
Registration
Attributes:
| Name | Type | Description |
|---|---|---|
flatten |
FlattenFunc
|
|
tree_def |
Type[TreeDef]
|
|
type |
Type[Any]
|
|
unflatten |
UnflattenFunc
|
|
TreeDef
Methods:
| Name | Description |
|---|---|
__str__ |
The generic string representation of a TreeDef. |
Attributes:
| Name | Type | Description |
|---|---|---|
aux |
Any
|
|
children |
tuple[TreeDef, ...]
|
|
is_leaf |
bool
|
|
is_none |
bool
|
|
type |
Type[Any]
|
|
__str__
__str__() -> str
The generic string representation of a TreeDef.
Developers are encouraged to override this method for custom pytree nodes.
TreePath
Methods:
| Name | Description |
|---|---|
__getitem__ |
|
__str__ |
|
__truediv__ |
|
get |
|
Attributes:
| Name | Type | Description |
|---|---|---|
paths |
tuple[PathKey, ...]
|
|
UnflattenFunc
register_pytree_node
register_pytree_node(type: Type[Any], flatten: FlattenFunc, unflatten: UnflattenFunc, tree_def: Type[TreeDef] = TreeDef) -> None
Register a custom pytree node type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type
|
Type[Any]
|
The custom pytree node type to register. |
required |
flatten
|
FlattenFunc
|
The function to flatten the custom pytree node. |
required |
unflatten
|
UnflattenFunc
|
The function to unflatten the custom pytree node. |
required |
tree_def
|
Type[TreeDef]
|
The TreeDef class for the custom pytree node. Defaults to TreeDef. |
TreeDef
|