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:
Edward Rusu
2022-03-02 07:51:06 -08:00
committed by GitHub
parent 15b5c6c29f
commit d1f35fe587
2 changed files with 23 additions and 27 deletions

View File

@@ -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