Skip to content

Commit

Permalink
Add support for (naive) batching
Browse files Browse the repository at this point in the history
  • Loading branch information
RedTachyon committed Dec 5, 2023
1 parent cf8baed commit f753f1a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions gymnasium/vector/utils/space_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
GraphInstance,
MultiBinary,
MultiDiscrete,
OneOf,
Sequence,
Space,
Text,
Expand Down Expand Up @@ -121,6 +122,11 @@ def _batch_space_dict(space: Dict, n: int = 1):
)


@batch_space.register(OneOf)
def _batch_space_oneof(space: OneOf, n: int = 1):
return Sequence(space)


@batch_space.register(Graph)
@batch_space.register(Text)
@batch_space.register(Sequence)
Expand Down Expand Up @@ -227,6 +233,11 @@ def _iterate_dict(space: Dict, items: dict[str, Any]):
yield OrderedDict({key: value for key, value in zip(keys, item)})


@iterate.register(Sequence)
def _iterate_sequence(space: Sequence, items: list[Any]):
yield from items


@singledispatch
def concatenate(
space: Space, items: Iterable, out: tuple[Any, ...] | dict[str, Any] | np.ndarray
Expand Down

0 comments on commit f753f1a

Please sign in to comment.