archimedes.tree.is_structΒΆ
- archimedes.tree.is_struct(obj: Any) bool ΒΆ
Check if an object is a registered struct class.
This function determines whether an object was created using the
struct()
decorator, which indicates it has special handling for tree operations.- Parameters:
obj (Any) β The object to check.
- Returns:
is_node β
True
if the object is a struct created with the decorator,False
otherwise.- Return type:
bool
Notes
When to use:
To check if an object will be handled specially by tree operations
For conditional logic based on whether an object is a custom struct
For debugging tree-related functionality
This function specifically checks for objects created with the
struct()
decorator, not built-in structured data types like lists, tuples, and dictionaries.Examples
>>> import archimedes as arc >>> import numpy as np >>> >>> @arc.struct >>> class State: ... x: np.ndarray ... v: np.ndarray >>> >>> state = State(np.zeros(3), np.ones(3)) >>> print(arc.tree.is_struct(state)) True >>> >>> # Regular dataclass is not a struct >>> from dataclasses import dataclass >>> >>> @dataclass >>> class RegularState: ... x: np.ndarray ... v: np.ndarray >>> >>> regular_state = RegularState(np.zeros(3), np.ones(3)) >>> print(arc.tree.is_struct(regular_state)) False >>> >>> # Built-in containers aren't custom structs >>> print(arc.tree.is_struct({"x": np.zeros(3)})) False
See also
struct
Decorator for creating tree-compatible dataclasses