Skip to content

unienv_interface.space.space_utils

reshape_batch_size

reshape_batch_size(space: Space, old_batch_shape: Tuple[int], new_batch_shape: Tuple[int]) -> Space

reshape_batch_size_in_data

reshape_batch_size_in_data(backend: ComputeBackend[BArrayType, BDeviceType, BDtypeType, BRNGType], data: Any, old_batch_shape: Tuple[int], new_batch_shape: Tuple[int]) -> Any

swap_batch_dims

swap_batch_dims(space: Space, dim1: int, dim2: int) -> Space

swap_batch_dims_in_data

swap_batch_dims_in_data(backend: ComputeBackend[BArrayType, BDeviceType, BDtypeType, BRNGType], data: Any, dim1: int, dim2: int) -> Any

batch_size

batch_size(space: Space) -> Optional[int]

Space does not support batching.

batch_space

batch_space(space: Space, n: int = 1) -> Space

batch_differing_spaces

batch_differing_spaces(spaces: Sequence[Space], device: Optional[Any] = None) -> Space

unbatch_spaces

unbatch_spaces(space: Space) -> Iterable[Space]

iterate

iterate(space: Space, items: Any) -> Iterator

get_at

get_at(space: Space, items: Any, index: ArrayAPIGetIndex) -> Any

set_at

set_at(space: Space, items: Any, index: ArrayAPISetIndex, value: Any) -> Any

concatenate

concatenate(space: Space, items: Iterable[Any], axis: int = 0) -> Any

construct_space_from_data_stream

construct_space_from_data_stream(data: Iterable[Any], backend: ComputeBackend, add_bounds: bool = True) -> Space

Construct a space from a stream of data.

Parameters:

Name Type Description Default
data Iterable[Any]

An iterable stream of data samples.

required
backend ComputeBackend

The compute backend to use for array operations.

required

Returns:

Name Type Description
Space Space

The constructed space.

construct_space_from_data

construct_space_from_data(data: Any, backend: ComputeBackend, candidate_space: Optional[Space] = None, add_bounds: bool = False) -> Space

is_flattenable

is_flattenable(space: Space, start_dim: int = 0) -> bool

flat_dim

flat_dim(space: Space, start_dim: int = 0) -> Optional[int]

flatten_space

flatten_space(space: Space, start_dim: int = 0) -> BoxSpace

flatten_data

flatten_data(space: Space, data: Any, start_dim: int = 0) -> BArrayType

unflatten_data

unflatten_data(space: Space, data: BArrayType, start_dim: int = 0) -> Any

space_to_json

space_to_json(space: Space) -> typing.Dict[str, Any]

Serialize a Space to a JSON-compatible dictionary.

Parameters:

Name Type Description Default
space Space

The space to serialize.

required

Returns:

Name Type Description
dict Dict[str, Any]

A JSON-compatible representation of the space.

json_to_space

json_to_space(json_data: Dict[str, Any], map_backend: ComputeBackend, map_device: Optional[BDeviceType]) -> Space

Deserialize a JSON-compatible dictionary into a Space instance.

Parameters:

Name Type Description Default
json_data dict

JSON-compatible space payload produced by :func:space_to_json.

required
map_backend ComputeBackend

Backend used to reconstruct backend-owned arrays and dtypes in the returned space.

required
map_device Optional[BDeviceType]

Optional device on which to place backend arrays created during deserialization.

required

Returns:

Name Type Description
Space Space

The deserialized space.