Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed .shape to be a property #2397

Merged
merged 3 commits into from
Sep 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gym/spaces/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, low, high, shape=None, dtype=np.float32):
if np.isscalar(high):
high = np.full(shape, high, dtype=dtype)

self.shape = shape
self._shape = shape
self.low = low
self.high = high

Expand Down
7 changes: 6 additions & 1 deletion gym/spaces/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Space(object):
def __init__(self, shape=None, dtype=None):
import numpy as np # takes about 300-400ms to import, so we load lazily

self.shape = None if shape is None else tuple(shape)
self._shape = None if shape is None else tuple(shape)
self.dtype = None if dtype is None else np.dtype(dtype)
self._np_random = None

Expand All @@ -33,6 +33,11 @@ def np_random(self):

return self._np_random

@property
def shape(self):
"""Return the shape of the space as an immutable property"""
return self._shape

def sample(self):
"""Randomly sample an element of this space. Can be
uniform or non-uniform sampling based on boundedness of space."""
Expand Down