archimedes.fieldΒΆ
- archimedes.field(
- static: bool = False,
- *,
- metadata: dict[str, Any] | None = None,
- **kwargs,
Create a field specification with struct-related metadata.
This function extends
dataclasses.field()with additional metadata to control how fields are treated in tree operations. Fields can be marked as static (metadata) or dynamic (data). Except for thestaticargument, all other arguments are passed directly todataclasses.field().- Parameters:
static (bool, default=False) β If True, the field is treated as static metadata rather than dynamic data. Static fields are preserved during tree transformations but not included in the flattened representation.
metadata (dict, optional) β Additional metadata to include in the field specification. This will be merged with the
staticsetting.**kwargs (dict) β Additional keyword arguments passed to
dataclasses.field().
- Returns:
field_object β A field specification with the appropriate metadata.
- Return type:
dataclasses.Field
Examples
>>> import structree as st >>> import numpy as np >>> >>> @st.struct >>> class Vehicle: ... position: np.ndarray ... velocity: np.ndarray ... mass: float = st.field(static=True, default=1000.0)
See also
structDecorator for creating tree-compatible dataclasses
register_dataclassRegister a dataclass as compatible with tree operations