Skip to content

Commit

Permalink
Unbreak contains for box
Browse files Browse the repository at this point in the history
  • Loading branch information
RedTachyon committed Dec 5, 2023
1 parent 785860f commit cf8baed
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions gymnasium/spaces/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,20 @@ def contains(self, x: Any) -> bool:
except (ValueError, TypeError):
return False

if not np.can_cast(x.dtype, self.dtype):
return False

if x.shape != self.shape:
return False

bounded_below = x >= self.low
bounded_above = x <= self.high

bounded = bounded_below & bounded_above
if self.nullable:
bounded |= np.isnan(x)

return bool(
np.can_cast(x.dtype, self.dtype)
and x.shape == self.shape
and np.all(bounded)
)
return np.all(bounded)

def to_jsonable(self, sample_n: Sequence[NDArray[Any]]) -> list[list]:
"""Convert a batch of samples from this space to a JSONable data type."""
Expand Down

0 comments on commit cf8baed

Please sign in to comment.