unienv_interface.transformations.transformation¶
DataTransformation
¶
Bases: ABC
Abstract transformation between two UniEnv data spaces.
Transformations are used by wrappers, storages, and batch views to adapt data while keeping enough metadata to derive the target space and, when supported, reconstruct the inverse transform.
get_target_space_from_source
abstractmethod
¶
get_target_space_from_source(source_space: Space[SourceDataT, SourceBDeviceT, SourceBDTypeT, SourceBDRNGT]) -> Optional[Space[TargetDataT, BDeviceType, BDtypeType, BRNGType]]
Returns the target space based on the source space (if supported, otherwise throws ValueError). This is useful for transformations that depend on the source space.
transform
abstractmethod
¶
transform(source_space: Space[SourceDataT, SourceBDeviceT, SourceBDTypeT, SourceBDRNGT], data: SourceDataT) -> TargetDataT
Apply the transformation to data drawn from source_space.
direction_inverse
¶
direction_inverse(source_space: Optional[Space[SourceDataT, SourceBDeviceT, SourceBDTypeT, SourceBDRNGT]] = None) -> Optional[DataTransformation]
Return the inverse transformation when one exists.
serialize
abstractmethod
¶
serialize(source_space: Optional[Space[SourceDataT, SourceBDeviceT, SourceBDTypeT, SourceBDRNGT]] = None) -> Dict[str, Any]
Serialize the transformation to a JSON-compatible dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_space
|
Optional[Space[SourceDataT, SourceBDeviceT, SourceBDTypeT, SourceBDRNGT]]
|
Optional source space context for transformations whose serialization depends on backend/device information. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict[str, Any]
|
A dictionary representation of the transformation containing:
- Parameters specific to the transformation type.
The helper |
deserialize_from
abstractmethod
classmethod
¶
deserialize_from(json_data: Dict[str, Any], source_space: Optional[Space[Any, BDeviceType, BDtypeType, BRNGType]] = None) -> DataTransformation
Deserialize a transformation from a JSON-compatible dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
json_data
|
Dict[str, Any]
|
The dictionary containing the transformation data |
required |
source_space
|
Optional[Space[Any, BDeviceType, BDtypeType, BRNGType]]
|
Optional source space context for transformations whose deserialization depends on backend/device information. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DataTransformation |
DataTransformation
|
A new instance of the transformation |