mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-17 20:39:12 +00:00
Box Boundedness determined using get_inf instead of np.inf (#2630)
* Box Boundedness determined using get_inf instead of np.inf * Store original array entries for determining boundedness * Capture the boundedness before casting away the np.inf * Removed requirement that integer spaces be bounded above and below * np full casts away the inf, so using dtype float for boundedness evaluation * Removed commented code * But the type ignore hint back in * Spacing change from black code formatter
This commit is contained in:
@@ -61,8 +61,14 @@ class Box(Space[np.ndarray]):
|
||||
)
|
||||
assert isinstance(shape, tuple)
|
||||
|
||||
# Capture the boundedness information before replacing np.inf with get_inf
|
||||
_low = np.full(shape, low, dtype=float) if np.isscalar(low) else low
|
||||
self.bounded_below = -np.inf < _low
|
||||
_high = np.full(shape, high, dtype=float) if np.isscalar(high) else high
|
||||
self.bounded_above = np.inf > _high
|
||||
|
||||
low = _broadcast(low, dtype, shape, inf_sign="-") # type: ignore
|
||||
high = _broadcast(high, dtype, shape, inf_sign="+")
|
||||
high = _broadcast(high, dtype, shape, inf_sign="+") # type: ignore
|
||||
|
||||
assert isinstance(low, np.ndarray)
|
||||
assert low.shape == shape, "low.shape doesn't match provided shape"
|
||||
@@ -82,10 +88,6 @@ class Box(Space[np.ndarray]):
|
||||
self.low_repr = _short_repr(self.low)
|
||||
self.high_repr = _short_repr(self.high)
|
||||
|
||||
# Boolean arrays which indicate the interval type for each coordinate
|
||||
self.bounded_below = -np.inf < self.low
|
||||
self.bounded_above = np.inf > self.high
|
||||
|
||||
super().__init__(self.shape, self.dtype, seed)
|
||||
|
||||
@property
|
||||
|
Reference in New Issue
Block a user